KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > callertrace > tests > AdjacencyMatrixTest


1 /*
2  * Created on Nov 8, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.hammurapi.inspectors.metrics.callertrace.tests;
8
9 import java.util.Vector JavaDoc;
10
11 import junit.framework.Test;
12 import junit.framework.TestCase;
13 import junit.framework.TestSuite;
14
15 import org.apache.log4j.Logger;
16 import org.apache.log4j.PropertyConfigurator;
17 import org.hammurapi.inspectors.metrics.callertrace.AdjacencyMatrix;
18 import org.hammurapi.inspectors.metrics.callertrace.BreadthSearch;
19 import org.hammurapi.inspectors.metrics.callertrace.DepthFirstSearch;
20 import org.hammurapi.inspectors.metrics.callertrace.EdgeImpl;
21 import org.hammurapi.inspectors.metrics.callertrace.MethodMap;
22 import org.hammurapi.inspectors.metrics.callertrace.MethodWrapper;
23 import org.hammurapi.inspectors.metrics.callertrace.MethodWrapperDeclaration;
24 import org.hammurapi.inspectors.metrics.callertrace.SearchMethod;
25 import org.hammurapi.inspectors.metrics.callertrace.Trace;
26 import org.hammurapi.inspectors.metrics.callertrace.TracedMethod;
27
28 public class AdjacencyMatrixTest extends TestCase {
29
30     private static Logger logger = Logger.getLogger(AdjacencyMatrixTest.class.getName());
31
32     public static Test suite() {
33         return new TestSuite(AdjacencyMatrixTest.class);
34     }
35
36     protected void setUp() throws Exception JavaDoc {
37
38         super.setUp();
39         PropertyConfigurator.configure("D:/a/Jegustator/0.7.0/src/config/TestRunLogConfig.txt");
40     }
41
42     /* (non_Javadoc)
43      * @see junit.framework.TestCase#tearDown()
44      */

45     protected void tearDown() throws Exception JavaDoc {
46
47         super.tearDown();
48     }
49
50     public void testSimpleField() {
51         AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
52
53         a.put("1", "1");
54         a.put("2", "2");
55         a.put("3","3");
56         assertTrue(!a.isVisited("1", "1"));
57         assertTrue(!a.isVisited("9999", "1"));
58         a.setVisitFlag("2","2");
59         assertTrue(a.isVisited("2","2"));
60         a.clearAllVisitFlags();
61         assertTrue(!a.isVisited("1","1"));
62         assertTrue(!a.isVisited("2","2"));
63         assertTrue(!a.isVisited("9999","1"));
64
65     }
66
67     public void testNodeEdge1() {
68             AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
69
70             a.put("1","2");
71             a.put("2","1");
72             a.put("3","5");
73             assertTrue(!a.isVisited("1","2"));
74             assertTrue(!a.isVisited("9999","1"));
75             a.setVisitFlag("1","2");
76             assertTrue(a.isVisited("1","2"));
77             a.clearAllVisitFlags();
78             assertTrue(!a.isVisited("1","2"));
79             assertTrue(!a.isVisited("2","1"));
80             assertTrue(!a.isVisited("9999","1"));
81
82         }
83
84 public void testExtractStartingNode(){
85     AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
86     assertTrue( "2".equals( a.extractStartingNode("2"+AdjacencyMatrix.KEY_SEPERATOR+"3") ));
87     assertTrue( "222222222222222".equals( a.extractStartingNode("222222222222222"+AdjacencyMatrix.KEY_SEPERATOR+"3") ));
88     assertTrue( "222222222222222".equals( a.extractStartingNode("222222222222222"+AdjacencyMatrix.KEY_SEPERATOR) ));
89     assertTrue( "".equals( a.extractStartingNode(AdjacencyMatrix.KEY_SEPERATOR) ));
90     assertTrue( "".equals( a.extractStartingNode("222222222222222") ));
91 }
92
93
94 public void testExtractEndNode(){
95     AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
96     assertTrue( "2".equals( a.extractSuccessorNode("3"+AdjacencyMatrix.KEY_SEPERATOR+"2") ));
97     assertTrue( "3".equals( a.extractSuccessorNode("222222222222222"+AdjacencyMatrix.KEY_SEPERATOR+"3") ));
98     assertTrue( "".equals( a.extractSuccessorNode("222222222222222"+AdjacencyMatrix.KEY_SEPERATOR) ));
99     assertTrue( "".equals( a.extractSuccessorNode(AdjacencyMatrix.KEY_SEPERATOR) ));
100     assertTrue( "".equals( a.extractSuccessorNode("222222222222222") ));
101 }
102
103
104
105     public void testAllSuccessorsOf() {
106         AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
107
108         a.put("1", "2");
109         a.put("2", "3");
110         a.put("1", "5");
111         a.put("1", "6");
112         a.put("6", "7");
113         assertTrue(!a.isVisited("9999", "1"));
114
115         //-- No Side effect
116
Vector JavaDoc vc = a.getAllSuccessorsOf("1");
117         assertTrue(vc.size() == 3);
118
119         vc = a.getAllNotVisitedSuccessorsOf("1");
120         assertTrue(vc.size() == 3);
121
122         //--Side effect
123
vc = a.getAllNotVisitedSuccessorsOf("1");
124         assertTrue(vc.size() == 0);
125
126         vc = a.getAllNotVisitedSuccessorsOf("2");
127         assertTrue(vc.size() == 1);
128     }
129
130     public void testDepthFirstSearch() {
131         AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
132         a.put("1", "2");
133             a.put("2", "3");
134             a.put("1", "5");
135             a.put("1", "6");
136             a.put("6", "7");
137
138 //
139
// Vector vc = a.getTraceOf("1");
140
// logger.debug( vc );
141
// assertTrue(vc.size() == 3);
142
// assertTrue("1".equals((String) vc.elementAt(0) ));
143
// assertTrue("6".equals((String) vc.elementAt(1) ));
144
// assertTrue("7".equals((String) vc.elementAt(2) ));
145
//
146

147 // vc = a.getTraceOf("1");
148
// logger.debug( vc );
149
// assertTrue(vc.size() == 2);
150
// assertTrue("1".equals((String) vc.elementAt(0) ));
151
// assertTrue("5".equals((String) vc.elementAt(1) ));
152
//
153
// vc = a.getTraceOf("1");
154
// logger.debug( vc );
155
// assertTrue(vc.size() == 3);
156
// assertTrue("1".equals((String) vc.elementAt(0) ));
157
// assertTrue("2".equals((String) vc.elementAt(1) ));
158
// assertTrue("3".equals((String) vc.elementAt(2) ));
159
//
160
// vc = a.getTraceOf("1");
161
// assertTrue(vc.size() == 1);
162
//
163
}
164
165
166     public void testBreadthSearchWithEdgeObjects() {
167         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
168         MethodMap mp = new MethodMap();
169
170         MethodWrapperDeclaration m1 = new MethodWrapperDeclaration("1", "A");
171         
172         // e1.setNodeA( m1 );
173
mp.put(m1.getMethodKey(), m1 );
174
175         MethodWrapperDeclaration m2 = new MethodWrapperDeclaration("2", "A");
176
177         EdgeImpl e1 = new EdgeImpl(m1.getMethodKey(), m2.getMethodKey());
178         mp.put(m2.getMethodKey(), m2 );
179
180         MethodWrapperDeclaration m3 = new MethodWrapperDeclaration("3", "A");
181         EdgeImpl e2 = new EdgeImpl(m2.getMethodKey(), m3.getMethodKey());
182         //e2.setNodeA( m2 );
183
//e2.setNodeB( m3 );
184
mp.put(m3.getMethodKey(), m3 );
185
186         MethodWrapperDeclaration m4 = new MethodWrapperDeclaration("4", "A");
187         EdgeImpl e3 = new EdgeImpl(m3.getMethodKey(), m4.getMethodKey());
188         //e3.setNodeA( m3 );
189
//e3.setNodeB( m4 );
190
mp.put(m4.getMethodKey(), m4 );
191
192         MethodWrapperDeclaration m5 = new MethodWrapperDeclaration("5", "A");
193         EdgeImpl e4 = new EdgeImpl(m3.getMethodKey(), m5.getMethodKey());
194         //e4.setNodeA( m3 );
195
//e4.setNodeB( m5 );
196
mp.put(m5.getMethodKey(), m5 );
197         a.setAllMethods(mp);
198
199         a.putEdge(e1);
200         a.putEdge(e2);
201         a.putEdge(e3);
202         a.putEdge(e4);
203         Vector JavaDoc vc = a.getSearchMethod().extractTraceListForKey("A>>1");
204          System.out.println(" 202" +vc);
205
206         // [[1, 2, 3, 4], [1, 2, 3, 5]]
207
// [[1, 2, 3, 5], [1, 2, 3, 4]]
208
// 202[[A>>1, A>>2, A>>3, A>>4], [A>>1, A>>2, A>>3, A>>5]]
209
// 202[[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
210
//-- the last item may vary
211
assertTrue("Vector Size should be 2 but is " +vc.size() , vc.size() == 2);
212         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
213         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(2)).getMethod().getSignature()));
214         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
215         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(2)).getMethod().getSignature()));
216     }
217
218
219     public void testBreadthSearchSimple() {
220         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
221         MethodMap mp = new MethodMap();
222         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
223         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
224         MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
225         MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
226         MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
227         mp.put(m1.getMethodKey(),m1);
228         mp.put(m2.getMethodKey(),m2);
229         mp.put(m3.getMethodKey(),m3);
230         mp.put(m4.getMethodKey(),m4);
231         mp.put(m5.getMethodKey(),m5);
232         
233         a.setAllMethods(mp);
234         a.put(m1.getMethodKey(), m2.getMethodKey());
235         a.put(m2.getMethodKey(), m3.getMethodKey());
236         a.put(m3.getMethodKey(), m4.getMethodKey());
237         a.put(m3.getMethodKey(), m5.getMethodKey());
238         Vector JavaDoc vc = a.getSearchMethod().extractTraceListForKey( "A>>1");
239         System.out.println(" 237 " +vc);
240         // 229 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
241
assertTrue(vc.size() == 2);
242         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
243         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(2)).getMethod().getSignature()));
244         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
245         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(2)).getMethod().getSignature()));
246     }
247
248     public void testBreadthSearchWithMultipleStartingPoints() {
249         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
250         MethodMap mp = new MethodMap();
251         MethodWrapper m1a = new MethodWrapperDeclaration("1", "A");
252         MethodWrapper m1b = new MethodWrapperDeclaration("1", "A");
253         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
254         MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
255         MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
256         MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
257         mp.put(m1a.getMethodKey(),m1a);
258         mp.put(m1b.getMethodKey(),m1b);
259         mp.put(m2.getMethodKey(),m2);
260         mp.put(m3.getMethodKey(),m3);
261         mp.put(m4.getMethodKey(),m4);
262         mp.put(m5.getMethodKey(),m5);
263         
264         a.setAllMethods(mp);
265         a.put(m1a.getMethodKey(), m2.getMethodKey());
266         a.put(m1b.getMethodKey(), m2.getMethodKey());
267         a.put(m2.getMethodKey(), m3.getMethodKey());
268         a.put(m3.getMethodKey(), m4.getMethodKey());
269         a.put(m3.getMethodKey(), m5.getMethodKey());
270         SearchMethod scm = a.getSearchMethod();
271         Vector JavaDoc vc = scm.extractTraceListForKey( "A>>1");
272         System.out.println(" 270 " +vc);
273         // 270 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2], [A>>1, A>>2, A>>3, A>>4]]
274
assertTrue(vc.size() == 3);
275     }
276
277
278
279
280     public void testBreadthSearchSimpleWithHashCode() {
281         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
282         MethodMap mp = new MethodMap();
283         
284         MethodWrapperDeclaration m1 = new MethodWrapperDeclaration("1", "A");
285         mp.put(m1.getMethodKey(), m1 );
286         
287         MethodWrapperDeclaration m2 = new MethodWrapperDeclaration("2", "A");
288         mp.put(m2.getMethodKey(), m2 );
289
290         MethodWrapperDeclaration m3 = new MethodWrapperDeclaration("3", "A");
291         mp.put(m3.getMethodKey(), m3 );
292
293         MethodWrapperDeclaration m4 = new MethodWrapperDeclaration("4", "A");
294         mp.put(m4.getMethodKey(), m4 );
295
296         MethodWrapperDeclaration m5 = new MethodWrapperDeclaration("5", "A");
297         mp.put(m5.getMethodKey(), m5 );
298
299     
300         a.setAllMethods(mp);
301         a.put(m1.getMethodKey(), m2.getMethodKey());
302         a.put( m2.getMethodKey() , m3.getMethodKey());
303         a.put(m3.getMethodKey(), m4.getMethodKey());
304         a.put(m3.getMethodKey(), m5.getMethodKey());
305
306         SearchMethod sm = a.getSearchMethod();
307         Vector JavaDoc vc =sm.extractTraceListForKey( "A>>1" );
308         System.out.println(" 306 Hash " +vc);
309         // 229 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
310
assertTrue(vc.size() == 2);
311         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
312         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0)).elementAt(2)).getMethod().getSignature()));
313         assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
314         assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1)).elementAt(2)).getMethod().getSignature()));
315         
316     }
317
318     public void testBreadthSearchCommonEndpoint() {
319         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
320         MethodMap mp = new MethodMap();
321         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
322         mp.put(m1.getMethodKey(), m1);
323         
324         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
325         mp.put(m2.getMethodKey(), m2);
326         
327         MethodWrapper m3 = new MethodWrapperDeclaration("3", "A") ;
328         mp.put(m3.getMethodKey(), m3);
329         
330         MethodWrapper m4 = new MethodWrapperDeclaration("4", "A") ;
331         mp.put(m4.getMethodKey(), m4);
332
333         MethodWrapper m5 = new MethodWrapperDeclaration("5", "A") ;
334         mp.put(m5.getMethodKey(), m5);
335         
336         MethodWrapper m6 = new MethodWrapperDeclaration("6", "A") ;
337         mp.put(m6.getMethodKey(), m6);
338
339         MethodWrapper m7 = new MethodWrapperDeclaration("7", "A") ;
340         mp.put(m7.getMethodKey(), m7);
341
342         MethodWrapper m8 = new MethodWrapperDeclaration("8", "A") ;
343         mp.put(m8.getMethodKey(), m8);
344
345         a.setAllMethods(mp);
346
347             a.put(m1.getMethodKey(), m2.getMethodKey());
348             a.put(m2.getMethodKey(), m3.getMethodKey());
349             a.put(m3.getMethodKey(), m8.getMethodKey());
350             
351             a.put(m1.getMethodKey(), m5.getMethodKey());
352             a.put(m1.getMethodKey(), m6.getMethodKey());
353             a.put(m6.getMethodKey(), m7.getMethodKey());
354             a.put(m7.getMethodKey(), m8.getMethodKey());
355             
356
357         Vector JavaDoc vc = a.getSearchMethod().extractTraceListForKey("A>>1");
358         System.out.println( " 356 "+ vc );
359         assertTrue(vc.size() == 3);
360
361         // 296 [[A>>1, A>>6, A>>7, A>>8], [A>>1, A>>5], [A>>1, A>>2, A>>3, A>>8]]
362
// 331 [[A>>1, A>>2, A>>3, A>>8], [A>>1, A>>6, A>>7, A>>8], [A>>1, A>>5]]
363
// 356 [[A>>1, A>>2, A>>3, A>>8], [A>>1], [A>>1], [A>>1, A>>5], [A>>1, A>>6, A>>7, A>>8]]
364

365         int sum1 = ((Trace)vc.elementAt(0)).size();
366         int sum2 = ((Trace)vc.elementAt(1)).size();
367         int sum3 = ((Trace)vc.elementAt(2)).size();
368         assertTrue( 10 == (sum1 + sum2 + sum3));
369         /*
370         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
371         assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(3)).getMethod().getSignature()));
372
373         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
374         assertTrue("5".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(1)).getMethod().getSignature()));
375
376         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(0)).getMethod().getSignature()));
377         assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(3)).getMethod().getSignature()));
378         */

379     }
380
381     //!! non intuitive traversal order
382
public void testBreadthSearchCommonMiddlepoint() {
383         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
384         MethodMap mp = new MethodMap();
385         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
386         mp.put(m1.getMethodKey(), m1);
387         
388         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
389         mp.put(m2.getMethodKey(), m2);
390         
391         MethodWrapper m3 = new MethodWrapperDeclaration("3", "A") ;
392         mp.put(m3.getMethodKey(), m3);
393         
394         MethodWrapper m4 = new MethodWrapperDeclaration("4", "A") ;
395         mp.put(m4.getMethodKey(), m4);
396
397         MethodWrapper m5 = new MethodWrapperDeclaration("5", "A") ;
398         mp.put(m5.getMethodKey(), m5);
399         
400         MethodWrapper m6 = new MethodWrapperDeclaration("6", "A") ;
401         mp.put(m6.getMethodKey(), m6);
402
403         MethodWrapper m7 = new MethodWrapperDeclaration("7", "A") ;
404         mp.put(m7.getMethodKey(), m7);
405
406         MethodWrapper m8 = new MethodWrapperDeclaration("8", "A") ;
407         mp.put(m8.getMethodKey(), m8);
408
409         a.setAllMethods(mp);
410
411             // [A>>1, A>>2, A>>3, A>>8
412
a.put(m1.getMethodKey(), m2.getMethodKey());
413             a.put(m2.getMethodKey(), m3.getMethodKey());
414             a.put(m3.getMethodKey(), m8.getMethodKey());
415             
416             // [A>>1, A>>5]
417
a.put(m1.getMethodKey(), m5.getMethodKey());
418             
419             // [A>>1, A>>6, A>>3, A>>7, A>>8]
420
a.put(m1.getMethodKey(), m6.getMethodKey());
421             a.put(m6.getMethodKey(), m3.getMethodKey());
422             a.put(m3.getMethodKey(), m7.getMethodKey());
423             a.put(m7.getMethodKey(), m8.getMethodKey());
424
425         SearchMethod sm = a.getSearchMethod();
426         Vector JavaDoc vc = sm.extractTraceListForKey( "A>>1");
427         System.out.println( " 419 " +vc );
428         // 335 [[A>>1, A>>5], [A>>1, A>>6, A>>3, A>>7, A>>8], [A>>1, A>>2, A>>3], [A>>1, A>>6, A>>3, A>>8]]
429
// 419 [[A>>1, A>>5], [A>>1], [A>>1], [A>>1, A>>2, A>>3, A>>7, A>>8], [A>>1, A>>6, A>>3], [A>>1, A>>2, A>>3, A>>8]]
430
// 419 [[A>>1, A>>5], [A>>1], [A>>1], [A>>1, A>>2, A>>3, A>>7, A>>8], [A>>1, A>>6, A>>3], [A>>1, A>>2, A>>3, A>>8]]
431
// 419 [[A>>1, A>>5], [A>>1], [A>>1], [A>>1, A>>2, A>>3, A>>7, A>>8], [A>>1, A>>6, A>>3], [A>>1, A>>2, A>>3, A>>8]]
432
// 419 [[A>>1, A>>2, A>>6, A>>5], [A>>1], [A>>1], [A>>1, A>>2, A>>6, A>>5], [A>>1, A>>2, A>>6, A>>5]]
433
// 419 [[A>>1, A>>5], [A>>1], [A>>1], [A>>1, A>>2, A>>3, A>>7, A>>8], [A>>1, A>>6, A>>3], [A>>1, A>>2, A>>3, A>>8]]
434
assertTrue(vc.size() == 4);
435         
436         int sum1 = ((Trace)vc.elementAt(0)).size();
437         int sum2 = ((Trace)vc.elementAt(1)).size();
438         int sum3 = ((Trace)vc.elementAt(2)).size();
439         int sum4 = ((Trace)vc.elementAt(3)).size();
440         
441         assertTrue( "total sum of traced methods should be 14 but is " + (sum1 + sum2 + sum3 + sum4), 14== (sum1 + sum2 + sum3 + sum4));
442         
443         /*
444         assertTrue( ((Trace)vc.elementAt(0)).size() == 2);
445         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
446         assertTrue("5".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(1)).getMethod().getSignature()));
447
448         assertTrue( ((Trace)vc.elementAt(1)).size() == 5);
449         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
450         assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(4)).getMethod().getSignature()));
451
452         assertTrue( ((Trace)vc.elementAt(2)).size() == 3);
453         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(0)).getMethod().getSignature()));
454         assertTrue("3".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(2)).getMethod().getSignature()));
455
456         assertTrue( ((Trace)vc.elementAt(3)).size() == 4);
457         assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(3)).elementAt(0)).getMethod().getSignature()));
458         assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(3)).elementAt(3)).getMethod().getSignature()));
459         */

460         }
461
462     public void testBreadthSearchSpider() {
463         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
464         MethodMap mp = new MethodMap();
465         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
466         mp.put(m1.getMethodKey(), m1);
467         
468         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
469         mp.put(m2.getMethodKey(), m2);
470         MethodWrapper m21 = new MethodWrapperDeclaration("2", "A") ;
471         mp.put(m21.getMethodKey(), m21);
472         
473         MethodWrapper m3 = new MethodWrapperDeclaration("3", "A") ;
474         mp.put(m3.getMethodKey(), m3);
475         
476         MethodWrapper m4 = new MethodWrapperDeclaration("4", "A") ;
477         mp.put(m4.getMethodKey(), m4);
478
479         MethodWrapper m5 = new MethodWrapperDeclaration("5", "A") ;
480         mp.put(m5.getMethodKey(), m5);
481
482         a.setAllMethods(mp);
483
484
485             a.put(m1.getMethodKey(), m2.getMethodKey());
486
487             a.put(m1.getMethodKey(), m21.getMethodKey());
488             
489             a.put(m1.getMethodKey(), m3.getMethodKey());
490
491             a.put(m1.getMethodKey(), m4.getMethodKey());
492             a.put(m4.getMethodKey(), m5.getMethodKey());
493             
494
495         SearchMethod sm = a.getSearchMethod();
496         Vector JavaDoc vc = sm.extractTraceListForKey( "A>>1");
497         System.out.println( " 502 " +vc );
498         // 502 [[A>>1, A>>2], [A>>1, A>>2], [A>>1, A>>3], [A>>1, A>>4, A>>5]]
499
// 502 [[A>>1, A>>2], [A>>1, A>>2], [A>>1, A>>3], [A>>1, A>>4, A>>5]]
500

501         assertTrue(vc.size() == 4);
502         }
503     
504     public void testBreadthSearchSimpleDoubleEdge() {
505         
506         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
507         MethodMap mp = new MethodMap();
508         
509         
510         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
511         mp.put(m1.getMethodKey(), m1);
512         
513         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
514         mp.put(m2.getMethodKey(), m2);
515         
516         a.setAllMethods(mp);
517             a.put(m1.getMethodKey(), m2.getMethodKey());
518         // a.put(m1.getMethodKey(), m2.getMethodKey());
519
// a.put(m1.getMethodKey(), m2.getMethodKey());
520

521         SearchMethod sm = a.getSearchMethod();
522         Vector JavaDoc vc = sm.extractTraceListForKey( "A>>1");
523         System.out.println( " 515 " +vc );
524
525         // 515 [[A>>1, A>>2]
526
assertTrue(vc.size() == 1);
527         }
528     
529     public void testBreadthSearchSimpleDoubleEdgeDoubleNode() {
530         
531         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
532         MethodMap mp = new MethodMap();
533         
534         
535         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
536         mp.put(m1.getMethodKey(), m1);
537         
538         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
539         mp.put(m2.getMethodKey(), m2);
540
541         MethodWrapper m3 = new MethodWrapperDeclaration("1", "A") ;
542         mp.put(m3.getMethodKey(), m3);
543         
544         MethodWrapper m4 = new MethodWrapperDeclaration("2", "A") ;
545         mp.put(m4.getMethodKey(), m4);
546
547         a.setAllMethods(mp);
548             a.put(m1.getMethodKey(), m2.getMethodKey());
549             a.put(m3.getMethodKey(), m4.getMethodKey());
550
551         SearchMethod sm = a.getSearchMethod();
552         Vector JavaDoc vc = sm.extractTraceListForKey( "A>>1");
553         System.out.println( " 546 " +vc );
554
555         // 546 [[A>>1, A>>2], [A>>1, A>>2]]
556
assertTrue(vc.size() == 2);
557         }
558
559     
560     public void testBreadthSearchSimpleDoubleEdgeDoubleNodeAndSomething() {
561         
562         AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
563         MethodMap mp = new MethodMap();
564         
565         
566         MethodWrapper m1 = new MethodWrapperDeclaration("1", "A") ;
567         mp.put(m1.getMethodKey(), m1);
568         
569         MethodWrapper m2 = new MethodWrapperDeclaration("2", "A") ;
570         mp.put(m2.getMethodKey(), m2);
571
572         MethodWrapper m3 = new MethodWrapperDeclaration("1", "A") ;
573         mp.put(m3.getMethodKey(), m3);
574         
575         MethodWrapper m4 = new MethodWrapperDeclaration("2", "A") ;
576         mp.put(m4.getMethodKey(), m4);
577
578         MethodWrapper m5 = new MethodWrapperDeclaration("3", "A") ;
579         mp.put(m5.getMethodKey(), m5);
580
581         a.setAllMethods(mp);
582             a.put(m1.getMethodKey(), m2.getMethodKey());
583             a.put(m3.getMethodKey(), m4.getMethodKey());
584             a.put(m4.getMethodKey(), m5.getMethodKey());
585
586         SearchMethod sm = a.getSearchMethod();
587         Vector JavaDoc vc = sm.extractTraceListForKey( "A>>1");
588         System.out.println( " 581 " +vc );
589
590         // 581 [[A>>1, A>>2], [A>>1, A>>2, A>>3]]
591
assertTrue(vc.size() == 2);
592         }
593
594
595     public void testBoolean() {
596         Boolean JavaDoc ret = new Boolean JavaDoc(false);
597         assertTrue(!ret.booleanValue());
598         ret = new Boolean JavaDoc(true);
599         assertTrue(ret.booleanValue());
600     }
601
602     public void testCloneTrace(){
603
604         Trace t = new Trace();
605         for (int i= 0; i< 3; i++){
606
607             MethodWrapperDeclaration m = new MethodWrapperDeclaration("lala"+i, "A");
608
609             TracedMethod tm = new TracedMethod(m);
610             tm.setMethod(m);
611             t.add(tm);
612         }
613         Trace cloneTrace = (Trace)t.clone();
614         assertTrue( cloneTrace.equals(t));
615     }
616
617 }
618
619
Popular Tags