import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; public class SimpleTest { public static Roosteraar roosteraar; @BeforeClass public static void init() { roosteraar = new LesRoosteraar(); } @Test public void test1() { List inputLessen = Arrays.asList( new Les(1, 1), new Les(2, 1), new Les(3, 1), new Les(5, 1), new Les(2, 2), new Les(4, 2), new Les(5, 2), new Les(1, 3), new Les(4, 3) ); List antw = roosteraar.planLessen(inputLessen); printOplossing(antw); oplossingGeldig(inputLessen, antw); oplossingOptimaal(antw, 5); } @Test public void test2() { List inputLessen = Arrays.asList( new Les(1,3), new Les(4,2), new Les(2,2), new Les(5,1), new Les(2,1), new Les(3,3), new Les(5,5), new Les(1,4), new Les(6,4), new Les(3,6) ); List antw = roosteraar.planLessen(inputLessen); printOplossing(antw); oplossingGeldig(inputLessen, antw); oplossingOptimaal(antw, 4); } @Test public void test3() { List inputLessen = Arrays.asList( new Les(2,4), new Les(3,3), new Les(1,3), new Les(1,3), new Les(2,4), new Les(4,1), new Les(4,2), new Les(2,1), new Les(1,4), new Les(3,2), new Les(4,2) ); List antw = roosteraar.planLessen(inputLessen); printOplossing(antw); oplossingGeldig(inputLessen, antw); oplossingOptimaal(antw, 5); } @Test public void test4(){ List inputLessen = Arrays.asList( new Les(1,1), new Les(1,2), new Les(2,1), new Les(2,2), new Les(3,1), new Les(3,2) ); List antw = roosteraar.planLessen(inputLessen); printOplossing(antw); oplossingGeldig(inputLessen, antw); oplossingOptimaal(antw, 4); } public static void oplossingGeldig(List inputLessen, List antw) { int count = 0; for(Lesuur lesuur: antw) { List lessen = lesuur.getLessen(); count += lessen.size(); Set lesgevers = new HashSet<>(); Set studentengroepen = new HashSet<>(); Assert.assertTrue("Je hebt lessen bijgemaakt.", inputLessen.containsAll(lessen)); for(Les les: lessen) { // Controleren of een lesgever niet meer dan één keer in een lesuur lesgeeft Assert.assertTrue("Lesgever " + les.getLesgever() + " is meerdere keren aanwezig in lesuur " + lesuur, lesgevers.add(les.getLesgever())); // Controleren of een studentengroep niet meer dan één les per uur volgt Assert.assertTrue("Studentengroep " + les.getStudentengroep() + " is meerdere keren aanwezig in lesuur " + lesuur, studentengroepen.add(les.getStudentengroep())); } } Assert.assertEquals("Niet alle lessen komen in het rooster voor.", inputLessen.size(), count); } public static void oplossingOptimaal(List antw, int maxUren) { Assert.assertTrue("Je oplossing is geldig, maar probeer het aantal lesuren nog te reduceren.", antw.size() <= maxUren); } public void printOplossing(List rooster) { for(int i=0; i