import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; public class SimpleTest { public static TruckLoader loader; @BeforeAll public static void init() { loader = new MyTruckLoader(); } @Test public void test1() { List input = List.of(12, 12, 12); List antw = loader.pack(input, 12); checkInput(input, antw, 12); Assertions.assertEquals(3, antw.size(), "Probeer het gebruikte aantal vrachtwagens te reduceren."); } @Test public void test2() { List input = List.of(4, 3, 4, 6, 2, 4, 5, 1, 1, 2, 2, 2, 4); List antw = loader.pack(input, 10); checkInput(input, antw, 10); Assertions.assertEquals(4, antw.size(), "Probeer het gebruikte aantal vrachtwagens te reduceren."); } @Test public void test3() { List input = List.of(1, 1, 1, 1, 8, 7, 6, 6); List antw = loader.pack(input, 9); checkInput(input, antw, 9); Assertions.assertTrue(antw.size() <= 5, "Probeer het gebruikte aantal vrachtwagens in jouw antwoord (" + antw.size() + ") te reduceren tot maximaal 5."); } @Test public void test4() { List input = List.of(7, 2, 2, 2, 2, 2, 3); List antw = loader.pack(input, 10); checkInput(input, antw, 10); Assertions.assertTrue(antw.size() <= 3, "Probeer het gebruikte aantal vrachtwagens in jouw antwoord (" + antw.size() + ") te reduceren tot maximaal 3."); } private void checkInput(List input, List antw, int capacity) { List antwItems = antw.stream().flatMap((truck)->truck.items().stream()).collect(Collectors.toList()); List inputKopie = new ArrayList<>(input); Collections.sort(inputKopie); Collections.sort(antwItems); Assertions.assertEquals(inputKopie, antwItems, "Items in vrachtwagens komen niet overeen met de gegeven objecten."); for (Truck truck : antw) { Assertions.assertEquals(capacity, truck.initialCapacity()); } } }