@Test public void testConnectNodes() { graph.connectNodes('A', 'F', -1); // negative cost graph.connectNodes('A', 'B', 1); // Already connected graph.connectNodes('G', 'D', 2); // already connected graph.connectNodes('H', 'A', 3); // H doesn't exists graph.connectNodes('D', 'H', 4); // H doesn't exists assertEquals(ORIGINAL_NUMBER_OF_NODES, graph.getNumberOfNodes()); assertEquals(ORIGINAL_NUMBER_OF_EDGES, graph.getNumberOfEdges()); assertEquals(ORIGINAL_EDGE_WEIGHT, graph.getTotalEdgeWeight()); assertFalse(graph.edgeExistsBetween('A', 'F')); assertTrue(graph.edgeExistsBetween('B', 'A')); assertTrue(graph.edgeExistsBetween('D', 'G')); assertFalse(graph.edgeExistsBetween('A', 'H')); assertFalse(graph.edgeExistsBetween('H', 'D')); graph.connectNodes('E', 'A', 9); assertEquals(ORIGINAL_NUMBER_OF_NODES, graph.getNumberOfNodes()); assertEquals(ORIGINAL_NUMBER_OF_EDGES + 1, graph.getNumberOfEdges()); assertEquals(ORIGINAL_EDGE_WEIGHT + 9, graph.getTotalEdgeWeight()); assertTrue(graph.edgeExistsBetween('A', 'E')); assertTrue(graph.edgeExistsBetween('E', 'A')); graph.connectNodes('F', 'E', 11); assertEquals(ORIGINAL_NUMBER_OF_NODES, graph.getNumberOfNodes()); assertEquals(ORIGINAL_NUMBER_OF_EDGES + 2, graph.getNumberOfEdges()); assertEquals(ORIGINAL_EDGE_WEIGHT + 20, graph.getTotalEdgeWeight()); assertTrue(graph.edgeExistsBetween('F', 'E')); assertTrue(graph.edgeExistsBetween('E', 'F')); }
@Test public void testBasicFeatures() { assertTrue(graph.contains('A')); assertTrue(graph.contains('E')); assertTrue(graph.contains('G')); assertFalse(graph.contains('H')); assertFalse(graph.contains('Q')); assertFalse(graph.contains('Ä')); assertTrue(graph.edgeExistsBetween('A', 'B')); assertTrue(graph.edgeExistsBetween('D', 'G')); assertTrue(graph.edgeExistsBetween('G', 'E')); assertTrue(graph.edgeExistsBetween('D', 'C')); assertFalse(graph.edgeExistsBetween('A', 'G')); assertFalse(graph.edgeExistsBetween('E', 'C')); assertFalse(graph.edgeExistsBetween('D', 'H')); assertFalse(graph.edgeExistsBetween('I', 'F')); assertEquals(ORIGINAL_NUMBER_OF_NODES, graph.getNumberOfNodes()); assertEquals(ORIGINAL_NUMBER_OF_EDGES, graph.getNumberOfEdges()); assertEquals(ORIGINAL_EDGE_WEIGHT, graph.getTotalEdgeWeight()); }