コード例 #1
0
 @Test
 public void testRemoveConnectedNode() {
   AdjacencyList<String, Integer> myGraph = new AdjacencyList<String, Integer>();
   boolean added = myGraph.addEdge("A", "B", new Integer(42));
   assertTrue(added);
   assertTrue(myGraph.adjacent("A", "B"));
   myGraph.removeNode("A");
   assertFalse(myGraph.adjacent("A", "B"));
 }
コード例 #2
0
 @Test
 public void testRemoveEdge() {
   AdjacencyList<String, Integer> myGraph = new AdjacencyList<String, Integer>();
   boolean added = myGraph.addEdge("A", "B", new Integer(42));
   assertTrue(added);
   assertTrue(myGraph.adjacent("A", "B"));
   Integer edgeRemoved = myGraph.removeEdge("A", "B");
   assertEquals(new Integer(42), edgeRemoved);
   assertFalse(myGraph.adjacent("A", "B"));
 }
コード例 #3
0
 @Test
 public void testAdjacent() {
   AdjacencyList<String, Integer> myGraph = new AdjacencyList<String, Integer>();
   // A ; B
   myGraph.addNode("A");
   myGraph.addNode("B");
   assertFalse(myGraph.adjacent("A", "B"));
   assertFalse(myGraph.adjacent("B", "A"));
   // A -> B
   myGraph.addEdge("A", "B", new Integer(18));
   assertTrue(myGraph.adjacent("A", "B"));
   assertFalse(myGraph.adjacent("B", "A"));
   // A -> B ; C
   myGraph.addNode("C");
   assertTrue(myGraph.adjacent("A", "B"));
   assertFalse(myGraph.adjacent("A", "C"));
   assertFalse(myGraph.adjacent("B", "A"));
   assertFalse(myGraph.adjacent("B", "C"));
   assertFalse(myGraph.adjacent("C", "A"));
   assertFalse(myGraph.adjacent("C", "B"));
   // C -> A -> B
   myGraph.addEdge("C", "A", new Integer(42));
   assertTrue(myGraph.adjacent("A", "B"));
   assertFalse(myGraph.adjacent("A", "C"));
   assertFalse(myGraph.adjacent("B", "A"));
   assertFalse(myGraph.adjacent("B", "C"));
   assertTrue(myGraph.adjacent("C", "A"));
   assertFalse(myGraph.adjacent("C", "B"));
 }