01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.build.opt;
18:
19: import junit.framework.TestCase;
20:
21: import org.geotools.graph.structure.DirectedEdge;
22: import org.geotools.graph.structure.DirectedGraph;
23: import org.geotools.graph.structure.DirectedNode;
24: import org.geotools.graph.structure.Graph;
25: import org.geotools.graph.structure.Node;
26: import org.geotools.graph.structure.opt.OptDirectedEdge;
27: import org.geotools.graph.structure.opt.OptDirectedNode;
28:
29: public class OptDirectedGraphBuilderTest extends TestCase {
30:
31: private OptDirectedGraphBuilder m_builder;
32:
33: public OptDirectedGraphBuilderTest(String name) {
34: super (name);
35: }
36:
37: protected void setUp() throws Exception {
38: super .setUp();
39:
40: m_builder = new OptDirectedGraphBuilder();
41: }
42:
43: public void test_buildNode() {
44: DirectedNode dn = (DirectedNode) m_builder.buildNode();
45:
46: assertTrue(dn != null);
47: assertTrue(dn instanceof OptDirectedNode);
48: }
49:
50: public void test_buildEdge() {
51: Node n1 = m_builder.buildNode();
52: Node n2 = m_builder.buildNode();
53:
54: DirectedEdge de = (DirectedEdge) m_builder.buildEdge(n1, n2);
55:
56: assertTrue(de != null);
57: assertTrue(de instanceof OptDirectedEdge);
58: assertTrue(de.getInNode() == n1);
59: assertTrue(de.getOutNode() == n2);
60: }
61:
62: public void test_addEdge() {
63: OptDirectedNode n1 = (OptDirectedNode) m_builder.buildNode();
64: n1.setInDegree(0);
65: n1.setOutDegree(1);
66:
67: OptDirectedNode n2 = (OptDirectedNode) m_builder.buildNode();
68: n2.setInDegree(1);
69: n2.setOutDegree(0);
70:
71: DirectedEdge e = (DirectedEdge) m_builder.buildEdge(n1, n2);
72:
73: m_builder.addEdge(e);
74:
75: assertTrue(m_builder.getEdges().contains(e));
76: assertTrue(n1.getOutEdges().contains(e));
77: assertTrue(n2.getInEdges().contains(e));
78: }
79:
80: public void test_getGraph() {
81: Graph graph = m_builder.getGraph();
82: assertTrue(graph instanceof DirectedGraph);
83: }
84: }
|