Package de.timefinder.algo.constraint

Source Code of de.timefinder.algo.constraint.MinGapsConstraintTest

/*
*  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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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 MinGapsConstraintTest extends TimeFinder2Tester {

    public MinGapsConstraintTest() {
    }

    @Before
    @Override
    public void setUp() {
        super.setUp();
        settings.setTimeslotsPerDay(4);
        settings.setNumberOfDays(5);

    }

    @Test
    public void testGetViolations() {
        Event ev1 = new Event(0, 2);
        Event ev2 = new Event(2, 1);
        Event ev3 = new Event(5, 1);
        Event ev4 = new Event(7, 1);

        List<Event> evList = new ArrayList<Event>();
        evList.add(ev1);
        evList.add(ev2);
        evList.add(ev3);
        evList.add(ev4);

        MinGapsConstraint constr = createConstraint(evList);
        assertEquals(1, constr.getViolations(null));

        constr.setCountEarly(true);
        assertEquals(2, constr.getViolations(null));
    }

    @Test
    public void testGetViolations2() {
        Event ev3 = new Event(5, 1);
        Event ev4 = new Event(7, 1);

        List<Event> evList = new ArrayList<Event>();
        evList.add(ev3);
        evList.add(ev4);

        MinGapsConstraint constr = createConstraint(evList);
        assertEquals(1, constr.getViolations(null));

        constr.setCountEarly(true);
        assertEquals(2, constr.getViolations(null));
    }

    MinGapsConstraint createConstraint(Collection<Event> evList) {
        MinGapsConstraint constr = new MinGapsConstraint(settings, evList);
        constr.setWeight(1f);
        constr.transformEvents(createTransformerMap(evList));
        return constr;
    }
}
TOP

Related Classes of de.timefinder.algo.constraint.MinGapsConstraintTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.