Search in sources :

Example 1 with RandomScheduler

use of org.absmodels.abs.plugin.debug.scheduling.RandomScheduler in project abstools by abstools.

the class SchedulingTest method testRandomScheduler.

@Test
public void testRandomScheduler() {
    RandomScheduler rs = new RandomScheduler(new Random());
    ScheduleOptions so = mock(ScheduleOptions.class);
    List<ScheduleAction> sal = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 100; i++) {
        sal.add(mock(ScheduleAction.class));
    }
    when(so.allOptions()).thenReturn(sal);
    when(so.numOptions()).thenReturn(100);
    ScheduleAction chosenActions;
    long seed = new Random().nextLong();
    rs = new RandomScheduler(new Random(seed));
    List<ScheduleAction> testActions = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 20; i++) {
        chosenActions = rs.choose(so);
        assertTrue(sal.contains(chosenActions));
        testActions.add(chosenActions);
    }
    RandomScheduler rs2 = new RandomScheduler(new Random(seed));
    List<ScheduleAction> testActions2 = new ArrayList<ScheduleAction>();
    for (int i = 0; i < 20; i++) {
        chosenActions = rs2.choose(so);
        assertTrue(sal.contains(chosenActions));
        testActions2.add(chosenActions);
    }
    for (int i = 0; i < testActions.size(); i++) {
        assertTrue("Element " + i + " should be equal!", testActions.get(i).equals(testActions2.get(i)));
    }
// TODO maybe write test for scheduling
}
Also used : ScheduleOptions(abs.backend.java.scheduling.ScheduleOptions) Random(java.util.Random) ScheduleAction(abs.backend.java.scheduling.ScheduleAction) RandomScheduler(org.absmodels.abs.plugin.debug.scheduling.RandomScheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ScheduleAction (abs.backend.java.scheduling.ScheduleAction)1 ScheduleOptions (abs.backend.java.scheduling.ScheduleOptions)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 RandomScheduler (org.absmodels.abs.plugin.debug.scheduling.RandomScheduler)1 Test (org.junit.Test)1