import graphlib.graphs.UndirectedGraph; import graphlib.edges.UndirectedEdge; import graphlib.nodes.Node; import org.junit.Assert; import org.junit.Test; import org.junit.Before; public class SimpleTest { private PadZoeker padZoeker; @Before public void before() { padZoeker = new BesmettingsPadZoeker(); } @Test public void testSingleEdge() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"); graph.addEdge(new UndirectedEdge(a, b, 10.0)); Assert.assertEquals(0.1, padZoeker.besmettingskans(graph, a, b, 1e-6), 1e-8); } @Test public void testTriangle() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"), c = graph.addNode("Carol"); graph.addEdge(new UndirectedEdge(a, b, 10.0)); graph.addEdge(new UndirectedEdge(b, c, 5.0)); graph.addEdge(new UndirectedEdge(c, a, 2.0)); Assert.assertEquals(1 - (1 - 0.1) * (1 - 0.5*0.2), padZoeker.besmettingskans(graph, a, b, 1e-6), 1e-8); Assert.assertEquals(1 - (1 - 0.2) * (1 - 0.1*0.5), padZoeker.besmettingskans(graph, b, c, 1e-6), 1e-8); Assert.assertEquals(1 - (1 - 0.5) * (1 - 0.1*0.2), padZoeker.besmettingskans(graph, c, a, 1e-6), 1e-8); } /* + * A / \ B * +---+ +---+ * \ / * + */ @Test public void testDashDiamondDash() { UndirectedGraph graph = new UndirectedGraph(); Node a = graph.addNode("Alice"), b = graph.addNode("Bob"), l = graph.addNode("Lizzie"), u = graph.addNode("Umar"), d = graph.addNode("David"), r = graph.addNode("Rupert"); graph.addEdge(new UndirectedEdge(a, l, 1.0)); graph.addEdge(new UndirectedEdge(l, u, 2.0)); graph.addEdge(new UndirectedEdge(u, r, 3.0)); graph.addEdge(new UndirectedEdge(l, d, 5.0)); graph.addEdge(new UndirectedEdge(d, r, 7.0)); graph.addEdge(new UndirectedEdge(r, b, 11.0)); Assert.assertEquals(0.017709563, padZoeker.besmettingskans(graph, a, b, 1e-6), 1e-8); } }