1 25 40 package org.jgrapht.graph; 41 42 import org.jgrapht.*; 43 44 45 50 public class GenericGraphsTest 51 extends EnhancedTestCase 52 { 53 54 56 Graph<Object , ? extends DefaultEdge> objectGraph; 57 Graph<FooVertex, FooEdge> fooFooGraph; 58 Graph<BarVertex, BarEdge> barBarGraph; 59 Graph<FooVertex, BarEdge> fooBarGraph; 60 61 63 66 public GenericGraphsTest(String name) 67 { 68 super(name); 69 } 70 71 73 75 public void testLegalInsertStringGraph() 76 { 77 String v1 = "Vertex1"; 78 Object v2 = "Vertex2"; 79 objectGraph.addVertex(v1); 80 objectGraph.addVertex(v2); 81 objectGraph.addEdge(v1, v2); 82 } 83 84 public void testLegalInsertFooGraph() 85 { 86 FooVertex v1 = new FooVertex(); 87 FooVertex v2 = new FooVertex(); 88 BarVertex vb1 = new BarVertex(); 89 BarVertex vb2 = new BarVertex(); 90 fooFooGraph.addVertex(v1); 91 fooFooGraph.addVertex(v2); 92 fooFooGraph.addVertex(vb1); 93 fooFooGraph.addVertex(vb2); 94 fooFooGraph.addEdge(v1, v2); 95 fooFooGraph.addEdge(vb1, vb2); 96 fooFooGraph.addEdge(v1, vb2); 97 fooFooGraph.addEdge(v1, v2, new BarEdge()); 98 fooFooGraph.addEdge(v1, vb2, new BarEdge()); 99 fooFooGraph.addEdge(vb1, vb2, new BarEdge()); 100 } 101 102 public void testLegalInsertBarGraph() 103 { 104 BarVertex v1 = new BarVertex(); 105 BarVertex v2 = new BarVertex(); 106 barBarGraph.addVertex(v1); 107 barBarGraph.addVertex(v2); 108 barBarGraph.addEdge(v1, v2); 109 } 110 111 public void testLegalInsertFooBarGraph() 112 { 113 FooVertex v1 = new FooVertex(); 114 FooVertex v2 = new FooVertex(); 115 BarVertex vb1 = new BarVertex(); 116 BarVertex vb2 = new BarVertex(); 117 fooFooGraph.addVertex(v1); 118 fooFooGraph.addVertex(v2); 119 fooFooGraph.addVertex(vb1); 120 fooFooGraph.addVertex(vb2); 121 fooFooGraph.addEdge(v1, v2); 122 fooFooGraph.addEdge(vb1, vb2); 123 fooFooGraph.addEdge(v1, vb2); 124 } 125 126 public void testAlissaHacker() 127 { 128 DirectedGraph<String , CustomEdge> g = 129 new DefaultDirectedGraph<String , CustomEdge>(CustomEdge.class); 130 g.addVertex("a"); 131 g.addVertex("b"); 132 g.addEdge("a", "b"); 133 CustomEdge custom = g.getEdge("a", "b"); 134 String s = custom.toString(); 135 assertEquals("Alissa P. Hacker", s); 136 } 137 138 141 protected void setUp() 142 { 143 objectGraph = 144 new DefaultDirectedGraph<Object , DefaultEdge>( 145 DefaultEdge.class); 146 fooFooGraph = new SimpleGraph<FooVertex, FooEdge>(FooEdge.class); 147 barBarGraph = new SimpleGraph<BarVertex, BarEdge>(BarEdge.class); 148 } 149 150 152 public static class CustomEdge 153 extends DefaultEdge 154 { 155 private static final long serialVersionUID = 1L; 156 157 public String toString() 158 { 159 return "Alissa P. Hacker"; 160 } 161 } 162 163 public static class FooEdge 164 extends DefaultEdge 165 { 166 private static final long serialVersionUID = 1L; 167 } 168 169 private class FooVertex 170 { 171 String str; 172 173 public FooVertex() 174 { 175 super(); 176 str = "empty foo"; 177 } 178 179 public FooVertex(String s) 180 { 181 str = s; 182 } 183 } 184 185 public static class BarEdge 186 extends FooEdge 187 { 188 private static final long serialVersionUID = 1L; 189 } 190 191 private class BarVertex 192 extends FooVertex 193 { 194 public BarVertex() 195 { 196 super("empty bar"); 197 } 198 199 public BarVertex(String s) 200 { 201 super(s); 202 } 203 } 204 } 205 | Popular Tags |