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
}
Aggregations