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.traverse.standard;
18:
19: import org.geotools.graph.GraphTestUtil;
20: import org.geotools.graph.build.GraphBuilder;
21: import org.geotools.graph.build.basic.BasicDirectedGraphBuilder;
22: import org.geotools.graph.structure.GraphVisitor;
23: import org.geotools.graph.structure.Graphable;
24: import org.geotools.graph.structure.Node;
25: import org.geotools.graph.traverse.basic.BasicGraphTraversal;
26: import org.geotools.graph.traverse.basic.DummyGraphWalker;
27:
28: public class DirectedDepthFirstIteratorTest extends
29: DepthFirstIteratorTest {
30:
31: public DirectedDepthFirstIteratorTest(String name) {
32: super (name);
33: }
34:
35: /**
36: * Create a graph with no bifurcations and do a full traversal from
37: * "last" node in graph. <BR>
38: * <BR>
39: * Expected: 1. Only last node should be visited.
40: */
41: public void test_7() {
42: final Node[] ends = GraphTestUtil.buildNoBifurcations(
43: builder(), 100);
44:
45: DummyGraphWalker walker = new DummyGraphWalker();
46: DirectedDepthFirstIterator iterator = new DirectedDepthFirstIterator();
47: BasicGraphTraversal traversal = new BasicGraphTraversal(
48: builder().getGraph(), walker, iterator);
49: traversal.init();
50:
51: iterator.setSource(ends[1]);
52: traversal.traverse();
53:
54: //ensure only last node visited
55: GraphVisitor visitor = new GraphVisitor() {
56: public int visit(Graphable component) {
57: if (component == ends[1])
58: assertTrue(component.isVisited());
59: else
60: assertTrue(!component.isVisited());
61: return (0);
62: }
63: };
64: builder().getGraph().visitNodes(visitor);
65: }
66:
67: protected DepthFirstIterator createIterator() {
68: return (new DirectedDepthFirstIterator());
69: }
70:
71: protected GraphBuilder createBuilder() {
72: return (new BasicDirectedGraphBuilder());
73: }
74: }
|