/*
* Copyright 2009 Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/
package de.timefinder.algo.constraint;
import de.timefinder.algo.util.TimeFinder2Tester;
import de.timefinder.data.Event;
import de.timefinder.data.algo.Assignment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net
*/
public class DifferentDayConstraintTest extends TimeFinder2Tester {
public DifferentDayConstraintTest() {
}
@Before
@Override
public void setUp() {
super.setUp();
}
@Test
public void testGetViolations() {
settings.setTimeslotsPerDay(4);
settings.setNumberOfDays(5);
Event ev1 = new Event(0, 2);
Event ev2 = new Event(0, 2);
Event ev3 = new Event(4, 1);
List<Event> list = new ArrayList<Event>();
list.add(ev1);
list.add(ev2);
list.add(ev3);
DifferentDayConstraint constr = createConstr(list);
Map<Event, Assignment> map = createTransformerMap(list);
constr.transformEvents(map);
assertEquals(2, constr.getViolations(map.get(ev1)));
assertEquals(2, constr.getViolations(map.get(ev2)));
assertEquals(0, constr.getViolations(map.get(ev3)));
}
private DifferentDayConstraint createConstr(List<Event> list) {
DifferentDayConstraint constr = new DifferentDayConstraint(settings, list);
constr.setWeight(1f);
return constr;
}
}