import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; public class SimpleTest { private static Planner planner; @BeforeClass public static void init() { planner = new MijnPlanner(); } @Test public void testList() { List taken = Arrays.asList( new Taak(4, 5), new Taak(10, 6), new Taak(3,4), new Taak(5, 10), new Taak(4, 8), new Taak(5, 13), new Taak(2, 4), new Taak(7, 17), new Taak(5, 12), new Taak(3, 9) ); List opl = Arrays.asList( taken.get(9), taken.get(4), taken.get(3), taken.get(8), taken.get(5), taken.get(7), taken.get(1) ); check(13, 88, planner.plan(Collections.unmodifiableCollection(taken))); } @Test public void testSet() { Taak taak = new Taak(1, 12); Set taken = new HashSet<>(Arrays.asList( new Taak(1, 4), new Taak(1, 8), new Taak(1, 3), taak, new Taak(1, 7) )); List opl = Arrays.asList( taak ); check(22, 34, planner.plan(Collections.unmodifiableCollection(taken))); } @Test public void testAlles() { List taken = Arrays.asList( new Taak(4, 5), new Taak(10, 6), new Taak(3,4), new Taak(5, 10), new Taak(4, 8), new Taak(8, 13), new Taak(2, 4), new Taak(7, 17), new Taak(7, 12), new Taak(10, 9) ); List opl = new ArrayList<>(taken); opl.sort(Comparator.comparingInt(Taak::getDeadline).thenComparing(Taak::getBoete)); check(0, 88, planner.plan(Collections.unmodifiableCollection(taken))); } @Test public void testLeeg() { Set taken = new HashSet<>(); check(0, 0, planner.plan(Collections.unmodifiableCollection(taken))); } public void check(int minBoete, int totaal, List antw) { int boete = totaal; for(int i = 0; i < antw.size(); i++) { Taak taak = antw.get(i); if(taak != null) { Assert.assertTrue(taak + " overschrijdt de deadline.", taak.getDeadline() > i); boete -= taak.getBoete(); } } Assert.assertEquals("Jouw boete is niet minimaal.", minBoete, boete); } }