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.basic;
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:
27: public class BasicDirectedGraphBuilderTest extends TestCase {
28:
29: private BasicDirectedGraphBuilder m_builder;
30:
31: public BasicDirectedGraphBuilderTest(String name) {
32: super (name);
33: }
34:
35: protected void setUp() throws Exception {
36: super .setUp();
37:
38: m_builder = new BasicDirectedGraphBuilder();
39: }
40:
41: public void test_buildNode() {
42: DirectedNode dn = (DirectedNode) m_builder.buildNode();
43: assertTrue(dn != null);
44: }
45:
46: public void test_buildEdge() {
47: Node n1 = m_builder.buildNode();
48: Node n2 = m_builder.buildNode();
49:
50: DirectedEdge de = (DirectedEdge) m_builder.buildEdge(n1, n2);
51:
52: assertTrue(de != null);
53: assertTrue(de.getInNode() == n1);
54: assertTrue(de.getOutNode() == n2);
55: }
56:
57: public void test_addEdge_0() {
58: DirectedNode n1 = (DirectedNode) m_builder.buildNode();
59: DirectedNode n2 = (DirectedNode) m_builder.buildNode();
60:
61: DirectedEdge e = (DirectedEdge) m_builder.buildEdge(n1, n2);
62:
63: m_builder.addEdge(e);
64:
65: assertTrue(m_builder.getEdges().contains(e));
66: assertTrue(n1.getOutEdges().contains(e));
67: assertTrue(n2.getInEdges().contains(e));
68: }
69:
70: public void test_addEdge_1() {
71: //add a loop edge, in degree == 1, out degree = 1, degree == 2
72: DirectedNode n1 = (DirectedNode) m_builder.buildNode();
73: DirectedEdge e = (DirectedEdge) m_builder.buildEdge(n1, n1);
74:
75: m_builder.addNode(n1);
76: m_builder.addEdge(e);
77:
78: assertTrue(n1.getInEdges().size() == 1);
79: assertTrue(n1.getOutEdges().size() == 1);
80: assertTrue(n1.getEdges().size() == 2);
81:
82: assertTrue(n1.getInDegree() == 1);
83: assertTrue(n1.getOutDegree() == 1);
84: assertTrue(n1.getDegree() == 2);
85: }
86:
87: public void test_getGraph() {
88: Graph graph = m_builder.getGraph();
89: assertTrue(graph instanceof DirectedGraph);
90: }
91: }
|