View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2005, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  
22  package org.dbunit.util.search;
23  
24  
25  
26  /**
27   * @author Felipe Leme (dbunit@felipeal.net)
28   * @version $Revision$
29   * @since Aug 25, 2005
30   */
31  
32  public class DepthFirstSearchTest extends AbstractSearchTestCase {
33  
34  
35    public void testEmptyGraph() throws Exception {
36      doIt();
37    }
38    
39    public void testSingleNode() throws Exception {
40      setInput(new String[] { A });
41      setOutput(new String[] { A });
42      doIt();
43    }
44  
45    public void testSingleEdge() throws Exception {
46      setInput(new String[] { A });
47      addEdges(A, new String[] { B });
48      setOutput(new String[] { B, A });
49      doIt();
50    }
51  
52    public void testSingleEdgeMultipleInput() throws Exception {
53      setInput(new String[] { A, B });
54      addEdges(A, new String[] { B });
55      setOutput(new String[] { B, A });
56      doIt();
57    }
58  
59    public void testSingleEdgeRepeatedInput() throws Exception {
60      setInput(new String[] { A, B, B, A, B });
61      addEdges(A, new String[] { B });
62      setOutput(new String[] { B, A });
63      doIt();
64    }
65  
66    public void testDisconnected() throws Exception {
67      setInput(new String[] { A, C });
68      addEdges(A, new String[] { B });
69      setOutput(new String[] { B, A, C });
70      doIt();
71    }
72  
73    public void testDisconnectedInverseOrder() throws Exception {
74      setInput(new String[] { C, A });
75      addEdges(A, new String[] { B });
76      setOutput(new String[] { B, A, C });
77      doIt();
78    }
79  
80    public void testMultipleEdgesOneSource() throws Exception {
81      setInput(new String[] { A });
82      addEdges(A, new String[] { B, C });
83      setOutput(new String[] { B, C, A });
84      doIt();
85    }
86  
87    public void testMultipleEdgesMultipleSources() throws Exception {
88      setInput(new String[] { A });
89      addEdges(A, new String[] { B, C });
90      addEdges(B, new String[] { D, C });
91      setOutput(new String[] { C, D, B, A });
92      doIt();
93    }
94  
95    public void testMultipleEdgesCycleFromA() throws Exception {
96      setInput(new String[] { A });
97      addEdges(A, new String[] { B });
98      addEdges(B, new String[] { C });
99      addEdges(C, new String[] { A });
100     setOutput(new String[] { C, B, A });
101     doIt();
102   }
103 
104   public void testMultipleEdgesCycleFromB() throws Exception {
105     setInput(new String[] { B });
106     addEdges(A, new String[] { B });
107     addEdges(B, new String[] { C });
108     addEdges(C, new String[] { A });
109     setOutput(new String[] { A, C, B });
110     doIt();
111   }
112 
113   public void testMultipleEdgesCycleFromBA() throws Exception {
114     setInput(new String[] { B, A });
115     addEdges(A, new String[] { B });
116     addEdges(B, new String[] { C });
117     addEdges(C, new String[] { A });
118     setOutput(new String[] { C, B, A });
119     doIt();
120   }
121 
122   public void testSelfCyclic() throws Exception {
123     setInput(new String[] { A });
124     addEdges(A, new String[] { A });
125     setOutput(new String[] { A });
126     doIt();
127   }
128 
129   public void testCyclicAndSelfCyclic() throws Exception {
130     setInput(new String[] { A });
131     addEdges(A, new String[] { A, B });
132     addEdges(B, new String[] { C });
133     addEdges(C, new String[] { A });
134     setOutput(new String[] { C, B, A });
135     doIt();
136   }
137 
138   public void testDisconnectedCycles() throws Exception {
139     setInput(new String[] { A, D });
140     addEdges(A, new String[] { B });
141     addEdges(B, new String[] { C });
142     addEdges(C, new String[] { A });
143     addEdges(D, new String[] { E });
144     addEdges(E, new String[] { F });
145     addEdges(F, new String[] { D });
146     setOutput(new String[] { F, E, D, C, B, A });
147     doIt();
148   }
149 
150   public void testConnectedCycle() throws Exception {
151     setInput(new String[] { A });
152     addEdges(A, new String[] { B });
153     addEdges(B, new String[] { C });
154     addEdges(C, new String[] { A, D });
155     addEdges(D, new String[] { E });
156     addEdges(E, new String[] { C });
157     setOutput(new String[] { E, D, C, B, A });
158     doIt();
159   }
160 
161   public void testBigConnectedCycle() throws Exception {
162     setInput(new String[] { A });
163     addEdges(A, new String[] { B });
164     addEdges(B, new String[] { C });
165     addEdges(C, new String[] { A, D });
166     addEdges(D, new String[] { E, B });
167     addEdges(E, new String[] { C });
168     setOutput(new String[] { E, D, C, B, A });
169     doIt();
170   }
171 
172   public void testMerge() throws Exception {
173     setInput(new String[] { A, C });
174     addEdges(A, new String[] { B });
175     addEdges(C, new String[] { A });
176     setOutput(new String[] { B, A, C });
177     doIt();
178   }
179 
180 }