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.util;
18:
19: import junit.framework.TestCase;
20:
21: import org.geotools.graph.GraphTestUtil;
22: import org.geotools.graph.build.GraphBuilder;
23: import org.geotools.graph.build.basic.BasicGraphBuilder;
24: import org.geotools.graph.util.graph.CycleDetector;
25:
26: public class CycleDetectorTest extends TestCase {
27: private GraphBuilder m_builder;
28:
29: public CycleDetectorTest(String name) {
30: super (name);
31: }
32:
33: protected void setUp() throws Exception {
34: super .setUp();
35:
36: m_builder = createBuilder();
37: }
38:
39: /**
40: * Create a graph without a cycle. <BR>
41: * <BR>
42: * Expected: 1. containsCycle() returns false
43: */
44: public void test_0() {
45: GraphTestUtil.buildNoBifurcations(builder(), 100);
46:
47: CycleDetector detector = new CycleDetector(builder().getGraph());
48: assertTrue(!detector.containsCycle());
49: }
50:
51: /**
52: * Create a graph that contains a cycle. <BR>
53: * <BR>
54: * Expected: 1. containsCycle returns true
55: */
56: public void test_1() {
57: GraphTestUtil.buildCircular(builder(), 100);
58:
59: CycleDetector detector = new CycleDetector(builder().getGraph());
60: assertTrue(detector.containsCycle());
61: }
62:
63: protected GraphBuilder createBuilder() {
64: return (new BasicGraphBuilder());
65: }
66:
67: protected GraphBuilder builder() {
68: return (m_builder);
69: }
70:
71: }
|