import graphlib.edges.UndirectedEdge; import graphlib.graphs.UndirectedGraph; import graphlib.nodes.Node; import org.junit.Assert; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; public class SimpleTest { Nightcrawler crawler = new BranchAndBoundCrawler(); @Test public void testSingleton() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"); Set> check = new HashSet<>(); check.add(new HashSet<>(graph.getAllNodes())); Assert.assertEquals(check, crawler.minimalCoverage(graph, 1.0) ); } @Test public void testSingleEdgeClose() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"); graph.addEdge(new UndirectedEdge(a, b, 5.0)); Set> check = new HashSet<>(); check.add(Collections.singleton(a)); check.add(Collections.singleton(b)); Assert.assertEquals(check, crawler.minimalCoverage(graph, 10.0)); } @Test public void testSingleEdgeFar() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"); graph.addEdge(new UndirectedEdge(a, b, 15.0)); Set> check = new HashSet<>(); check.add(new HashSet<>(Arrays.asList(a, b))); Assert.assertEquals(check, crawler.minimalCoverage(graph, 10.0)); } @Test public void testVShapeMiddle() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"), m = graph.addNode("Mallory"); graph.addEdge(new UndirectedEdge(a, m, 10.0)); graph.addEdge(new UndirectedEdge(m, b, 10.0)); Set> check = new HashSet<>(); check.add(Collections.singleton(m)); Assert.assertEquals(check, crawler.minimalCoverage(graph, 10.0)); } @Test public void testTriangleAny() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"), c = graph.addNode("Carol"); graph.addEdge(new UndirectedEdge(a, b, 5.0)); graph.addEdge(new UndirectedEdge(b, c, 5.0)); graph.addEdge(new UndirectedEdge(c, a, 5.0)); Set> check = new HashSet<>(); check.add(Collections.singleton(a)); check.add(Collections.singleton(b)); check.add(Collections.singleton(c)); Assert.assertEquals(check, crawler.minimalCoverage(graph, 10.0)); } @Test public void testTriangleSingle() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"), m = graph.addNode("Mallory"); graph.addEdge(new UndirectedEdge(a, m, 5.0)); graph.addEdge(new UndirectedEdge(m, b, 5.0)); graph.addEdge(new UndirectedEdge(a, b, 10.0)); Set> check = new HashSet<>(); check.add(Collections.singleton(m)); Assert.assertEquals(check, crawler.minimalCoverage(graph, 10.0)); } }