1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.test.graph.alg.traversal; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
import net.sourceforge.combean.graph.NumberNode; |
26 | |
import net.sourceforge.combean.graph.alg.traversal.DFSNodeNumberingVisitor; |
27 | |
import net.sourceforge.combean.graph.alg.traversal.RecursiveDFSImpl; |
28 | |
import net.sourceforge.combean.interfaces.graph.Graph; |
29 | |
import net.sourceforge.combean.interfaces.graph.alg.traverse.DepthFirstSearch; |
30 | |
import net.sourceforge.combean.samples.simplegraphs.DirectedCircle; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class TestDFSNodeNumberingVisitor extends TestCase { |
37 | |
|
38 | 3 | private DFSNodeNumberingVisitor numberingVis = null; |
39 | 3 | private DepthFirstSearch dfsAlg = null; |
40 | |
|
41 | |
private static final int CIRCLESIZE = 5; |
42 | 3 | private Graph circle = null; |
43 | |
|
44 | |
public static void main(String[] args) { |
45 | 0 | junit.textui.TestRunner.run(TestDFSNodeNumberingVisitor.class); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
protected void setUp() throws Exception { |
52 | 3 | super.setUp(); |
53 | |
|
54 | 3 | this.circle = new DirectedCircle(CIRCLESIZE); |
55 | 3 | this.dfsAlg = new RecursiveDFSImpl(); |
56 | 3 | this.dfsAlg.setGraph(this.circle); |
57 | 3 | this.numberingVis = new DFSNodeNumberingVisitor(); |
58 | 3 | this.dfsAlg.setVisitor(this.numberingVis); |
59 | 3 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
protected void tearDown() throws Exception { |
65 | 3 | super.tearDown(); |
66 | 3 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public TestDFSNodeNumberingVisitor(String name) { |
73 | 3 | super(name); |
74 | 3 | } |
75 | |
|
76 | |
public final void testGetDfsNum() { |
77 | 3 | this.dfsAlg.setLocalStartNode(new NumberNode(0)); |
78 | 3 | this.dfsAlg.run(); |
79 | 18 | for (int i = 0; i < CIRCLESIZE; i++) { |
80 | 15 | NumberNode v = new NumberNode(i); |
81 | 15 | assertEquals("by construction dfs number must equal node number", |
82 | |
i+1, this.numberingVis.getDfsNum(v)); |
83 | |
} |
84 | 3 | } |
85 | |
|
86 | |
} |