import org.junit.Assert; import org.junit.Test; import java.util.BitSet; import java.util.Collection; import java.util.HashSet; public class SimpleTest { @Test public void testTriangle(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("Bw"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 1); } @Test public void testComplete(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("E~~w"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 1); } @Test public void testEmpty(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("E???"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 6); } @Test public void test4Cykel(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("Cl"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 2); } @Test public void test5Cykel(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("Dhc"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 2); } @Test public void test6Cykel(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("EhEG"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 2); } @Test public void test7Cykel(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("FhCKG"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 3); } @Test public void testFruchtGraph(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("KhCKM?_EGK?L"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 3); } @Test public void testPetersenGraph(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("IheA@GUAo"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 3); } @Test public void testBrinkmannGraph(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("TQIQU@_K?o@_@___?CGA_?I??S_?T_?Io@AK"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 6); } @Test public void testPairs(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("U`?G?C??G??@????_???@?????G?????EiiiTTTO"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 2); } @Test public void testTree(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("LsaAA?_C?O@?@?"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 5); } @Test public void testTree2(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("R[aCCA?OA?G?O?O?G?@??G??_?@???"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 3); } @Test public void testNonGreedy(){ Vertegenwoordigers vertegenwoordigers = new MyVertegenwoordigers(); BitGraph graph = new BitGraph("TsaBA`GP@?A?A?@?O?C??_??_??_??O??C??"); var solution = vertegenwoordigers.optimaleSelectie(graph); check(graph, solution, 5); } static void check(BitGraph graph, Collection solution, int optimal){ Assert.assertEquals("Not all selected vertices are unique.", solution.size(), new HashSet<>(solution).size()); for (int v : solution) { Assert.assertTrue("Vertex " + v + " does not belong to the graph.", v >= 0 && v < graph.order()); } checkDominating(graph, solution); Assert.assertEquals("Your solution is not optimal.", optimal, solution.size()); } static void checkDominating(BitGraph graph, Collection solution){ BitSet covered = new BitSet(graph.order()); for (int v : solution) { covered.or(graph.adjacency(v)); covered.set(v); } for (int v = 0; v < graph.order(); v++) { Assert.assertTrue("Vertex " + v + " is not covered by your selection.", covered.get(v)); } } }