import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; public class SimpleTest { private static Planner planner; @BeforeAll public static void init() { planner = new MyPlanner(); } @Test public void testList() { List tasks = Arrays.asList( new Task(4, 5), new Task(10, 6), new Task(3,4), new Task(5, 10), new Task(4, 8), new Task(5, 13), new Task(2, 4), new Task(7, 17), new Task(5, 12), new Task(3, 9) ); Set expected = Set.of( tasks.get(9), tasks.get(4), tasks.get(3), tasks.get(8), tasks.get(5), tasks.get(7), tasks.get(1) ); List solution = planner.plan(Collections.unmodifiableCollection(tasks)); check(13, 88, solution, expected); } @Test public void testSet() { Task task = new Task(1, 12); Set tasks = new HashSet<>(Arrays.asList( new Task(1, 4), new Task(1, 8), new Task(1, 3), task, new Task(1, 7) )); Set expected = Set.of( task ); List solution = planner.plan(Collections.unmodifiableCollection(tasks)); check(22, 34, solution, expected); } @Test public void testAlles() { List tasks = Arrays.asList( new Task(4, 5), new Task(10, 6), new Task(3,4), new Task(5, 10), new Task(4, 8), new Task(8, 13), new Task(2, 4), new Task(7, 17), new Task(7, 12), new Task(10, 9) ); Set expected = new HashSet<>(tasks); List solution = planner.plan(Collections.unmodifiableCollection(tasks)); check(0, 88, solution, expected); } @Test public void testLeeg() { Set expected = new HashSet<>(); List solution = planner.plan(Collections.unmodifiableCollection(expected)); check(0, 0, solution, expected); } public void check(int minPenalty, int total, List sol, Set exp) { int penalty = total; for(int i = 0; i < sol.size(); i++) { Task task = sol.get(i); if(task != null) { Assertions.assertTrue(task.deadline() > i, task + " overschrijdt de deadline."); penalty -= task.penalty(); Assertions.assertTrue(exp.contains(task)); } } Assertions.assertEquals(minPenalty, penalty, "Jouw penalty is niet minimaal."); } }