Beispiel #1
0
 @Test
 public void testSelfEdges() {
   UndirectedGraph q = new UndirectedGraph();
   q.add();
   q.add();
   q.add();
   q.add();
   q.add();
   q.add();
   q.add();
   q.add();
   q.add(1, 8);
   q.add(1, 1);
   q.add(1, 2);
   q.add(1, 3);
   q.add(1, 4);
   ArrayList<Integer> output2 = new ArrayList<>();
   for (int node : q.successors(1)) {
     output2.add(node);
   }
   List<Integer> expected2 = Arrays.asList(8, 1, 2, 3, 4);
   assertTrue(output2.equals(expected2));
   assertEquals(5, q.edgeSize());
   q.remove(2);
   ArrayList<Integer> output3 = new ArrayList<>();
   for (int node : q.successors(1)) {
     output3.add(node);
   }
   List<Integer> expected3 = Arrays.asList(8, 1, 3, 4);
   assertTrue(output3.equals(expected3));
   assertEquals(4, q.edgeSize());
 }
Beispiel #2
0
 @Test
 public void undirectedGraph() {
   UndirectedGraph g = new UndirectedGraph();
   g.add();
   g.add();
   g.add(1, 2);
   assertEquals(1, g.edgeSize());
   assertEquals(2, g.successor(1, 0));
   assertEquals(2, g.predecessor(1, 0));
   g.add();
   g.add();
   g.add(1, 3);
   g.add(1, 4);
   ArrayList<Integer> output = new ArrayList<>();
   for (int node : g.successors(1)) {
     output.add(node);
   }
   List<Integer> expected = Arrays.asList(2, 3, 4);
   assertTrue(output.equals(expected));
   g.remove(1, 4);
   assertFalse(g.contains(1, 4));
   assertFalse(g.contains(4, 1));
   UndirectedGraph p = new UndirectedGraph();
   p.add();
   p.add();
   p.add();
   p.add();
   p.add(2, 1);
   p.add(3, 1);
   p.add(4, 1);
   p.add(2, 3);
   p.remove(1);
   assertEquals(1, p.edgeSize());
 }