Source Code Cross Referenced for AdjacencyMatrixTest.java in  » Code-Analyzer » hammurapi-3.20.0.3 » org » hammurapi » inspectors » metrics » callertrace » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » hammurapi 3.20.0.3 » org.hammurapi.inspectors.metrics.callertrace.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Nov 8, 2003
003:         *
004:         * To change the template for this generated file go to
005:         * Window>Preferences>Java>Code Generation>Code and Comments
006:         */
007:        package org.hammurapi.inspectors.metrics.callertrace.tests;
008:
009:        import java.util.Vector;
010:
011:        import junit.framework.Test;
012:        import junit.framework.TestCase;
013:        import junit.framework.TestSuite;
014:
015:        import org.apache.log4j.Logger;
016:        import org.apache.log4j.PropertyConfigurator;
017:        import org.hammurapi.inspectors.metrics.callertrace.AdjacencyMatrix;
018:        import org.hammurapi.inspectors.metrics.callertrace.BreadthSearch;
019:        import org.hammurapi.inspectors.metrics.callertrace.DepthFirstSearch;
020:        import org.hammurapi.inspectors.metrics.callertrace.EdgeImpl;
021:        import org.hammurapi.inspectors.metrics.callertrace.MethodMap;
022:        import org.hammurapi.inspectors.metrics.callertrace.MethodWrapper;
023:        import org.hammurapi.inspectors.metrics.callertrace.MethodWrapperDeclaration;
024:        import org.hammurapi.inspectors.metrics.callertrace.SearchMethod;
025:        import org.hammurapi.inspectors.metrics.callertrace.Trace;
026:        import org.hammurapi.inspectors.metrics.callertrace.TracedMethod;
027:
028:        public class AdjacencyMatrixTest extends TestCase {
029:
030:            private static Logger logger = Logger
031:                    .getLogger(AdjacencyMatrixTest.class.getName());
032:
033:            public static Test suite() {
034:                return new TestSuite(AdjacencyMatrixTest.class);
035:            }
036:
037:            protected void setUp() throws Exception {
038:
039:                super .setUp();
040:                PropertyConfigurator
041:                        .configure("D:/a/Jegustator/0.7.0/src/config/TestRunLogConfig.txt");
042:            }
043:
044:            /* (non_Javadoc)
045:             * @see junit.framework.TestCase#tearDown()
046:             */
047:            protected void tearDown() throws Exception {
048:
049:                super .tearDown();
050:            }
051:
052:            public void testSimpleField() {
053:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
054:
055:                a.put("1", "1");
056:                a.put("2", "2");
057:                a.put("3", "3");
058:                assertTrue(!a.isVisited("1", "1"));
059:                assertTrue(!a.isVisited("9999", "1"));
060:                a.setVisitFlag("2", "2");
061:                assertTrue(a.isVisited("2", "2"));
062:                a.clearAllVisitFlags();
063:                assertTrue(!a.isVisited("1", "1"));
064:                assertTrue(!a.isVisited("2", "2"));
065:                assertTrue(!a.isVisited("9999", "1"));
066:
067:            }
068:
069:            public void testNodeEdge1() {
070:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
071:
072:                a.put("1", "2");
073:                a.put("2", "1");
074:                a.put("3", "5");
075:                assertTrue(!a.isVisited("1", "2"));
076:                assertTrue(!a.isVisited("9999", "1"));
077:                a.setVisitFlag("1", "2");
078:                assertTrue(a.isVisited("1", "2"));
079:                a.clearAllVisitFlags();
080:                assertTrue(!a.isVisited("1", "2"));
081:                assertTrue(!a.isVisited("2", "1"));
082:                assertTrue(!a.isVisited("9999", "1"));
083:
084:            }
085:
086:            public void testExtractStartingNode() {
087:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
088:                assertTrue("2".equals(a.extractStartingNode("2"
089:                        + AdjacencyMatrix.KEY_SEPERATOR + "3")));
090:                assertTrue("222222222222222".equals(a
091:                        .extractStartingNode("222222222222222"
092:                                + AdjacencyMatrix.KEY_SEPERATOR + "3")));
093:                assertTrue("222222222222222".equals(a
094:                        .extractStartingNode("222222222222222"
095:                                + AdjacencyMatrix.KEY_SEPERATOR)));
096:                assertTrue("".equals(a
097:                        .extractStartingNode(AdjacencyMatrix.KEY_SEPERATOR)));
098:                assertTrue("".equals(a.extractStartingNode("222222222222222")));
099:            }
100:
101:            public void testExtractEndNode() {
102:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
103:                assertTrue("2".equals(a.extractSuccessorNode("3"
104:                        + AdjacencyMatrix.KEY_SEPERATOR + "2")));
105:                assertTrue("3".equals(a.extractSuccessorNode("222222222222222"
106:                        + AdjacencyMatrix.KEY_SEPERATOR + "3")));
107:                assertTrue("".equals(a.extractSuccessorNode("222222222222222"
108:                        + AdjacencyMatrix.KEY_SEPERATOR)));
109:                assertTrue("".equals(a
110:                        .extractSuccessorNode(AdjacencyMatrix.KEY_SEPERATOR)));
111:                assertTrue("".equals(a.extractSuccessorNode("222222222222222")));
112:            }
113:
114:            public void testAllSuccessorsOf() {
115:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
116:
117:                a.put("1", "2");
118:                a.put("2", "3");
119:                a.put("1", "5");
120:                a.put("1", "6");
121:                a.put("6", "7");
122:                assertTrue(!a.isVisited("9999", "1"));
123:
124:                //-- No Side effect
125:                Vector vc = a.getAllSuccessorsOf("1");
126:                assertTrue(vc.size() == 3);
127:
128:                vc = a.getAllNotVisitedSuccessorsOf("1");
129:                assertTrue(vc.size() == 3);
130:
131:                //--Side effect
132:                vc = a.getAllNotVisitedSuccessorsOf("1");
133:                assertTrue(vc.size() == 0);
134:
135:                vc = a.getAllNotVisitedSuccessorsOf("2");
136:                assertTrue(vc.size() == 1);
137:            }
138:
139:            public void testDepthFirstSearch() {
140:                AdjacencyMatrix a = new AdjacencyMatrix(new DepthFirstSearch());
141:                a.put("1", "2");
142:                a.put("2", "3");
143:                a.put("1", "5");
144:                a.put("1", "6");
145:                a.put("6", "7");
146:
147:                //
148:                //		Vector vc = a.getTraceOf("1");
149:                //		logger.debug( vc );
150:                //		assertTrue(vc.size() == 3);
151:                //		assertTrue("1".equals((String) vc.elementAt(0) ));
152:                //		assertTrue("6".equals((String) vc.elementAt(1) ));
153:                //		assertTrue("7".equals((String) vc.elementAt(2) ));
154:                //
155:
156:                //		vc = a.getTraceOf("1");
157:                //		logger.debug( vc );
158:                //		assertTrue(vc.size() == 2);
159:                //		assertTrue("1".equals((String) vc.elementAt(0) ));
160:                //		assertTrue("5".equals((String) vc.elementAt(1) ));
161:                //
162:                //		vc = a.getTraceOf("1");
163:                //		logger.debug( vc );
164:                //		assertTrue(vc.size() == 3);
165:                //		assertTrue("1".equals((String) vc.elementAt(0) ));
166:                //		assertTrue("2".equals((String) vc.elementAt(1) ));
167:                //		assertTrue("3".equals((String) vc.elementAt(2) ));
168:                //
169:                //		vc = a.getTraceOf("1");
170:                //		assertTrue(vc.size() == 1);
171:                //
172:            }
173:
174:            public void testBreadthSearchWithEdgeObjects() {
175:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
176:                MethodMap mp = new MethodMap();
177:
178:                MethodWrapperDeclaration m1 = new MethodWrapperDeclaration("1",
179:                        "A");
180:
181:                // e1.setNodeA( m1 );
182:                mp.put(m1.getMethodKey(), m1);
183:
184:                MethodWrapperDeclaration m2 = new MethodWrapperDeclaration("2",
185:                        "A");
186:
187:                EdgeImpl e1 = new EdgeImpl(m1.getMethodKey(), m2.getMethodKey());
188:                mp.put(m2.getMethodKey(), m2);
189:
190:                MethodWrapperDeclaration m3 = new MethodWrapperDeclaration("3",
191:                        "A");
192:                EdgeImpl e2 = new EdgeImpl(m2.getMethodKey(), m3.getMethodKey());
193:                //e2.setNodeA( m2 );
194:                //e2.setNodeB( m3 );
195:                mp.put(m3.getMethodKey(), m3);
196:
197:                MethodWrapperDeclaration m4 = new MethodWrapperDeclaration("4",
198:                        "A");
199:                EdgeImpl e3 = new EdgeImpl(m3.getMethodKey(), m4.getMethodKey());
200:                //e3.setNodeA( m3 );
201:                //e3.setNodeB( m4 );
202:                mp.put(m4.getMethodKey(), m4);
203:
204:                MethodWrapperDeclaration m5 = new MethodWrapperDeclaration("5",
205:                        "A");
206:                EdgeImpl e4 = new EdgeImpl(m3.getMethodKey(), m5.getMethodKey());
207:                //e4.setNodeA( m3 );
208:                //e4.setNodeB( m5 );
209:                mp.put(m5.getMethodKey(), m5);
210:                a.setAllMethods(mp);
211:
212:                a.putEdge(e1);
213:                a.putEdge(e2);
214:                a.putEdge(e3);
215:                a.putEdge(e4);
216:                Vector vc = a.getSearchMethod().extractTraceListForKey("A>>1");
217:                System.out.println("§ 202" + vc);
218:
219:                // [[1, 2, 3, 4], [1, 2, 3, 5]]
220:                // [[1, 2, 3, 5], [1, 2, 3, 4]]
221:                //  § 202[[A>>1, A>>2, A>>3, A>>4], [A>>1, A>>2, A>>3, A>>5]]
222:                // § 202[[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
223:                //-- the last item may vary
224:                assertTrue("Vector Size should be 2 but is " + vc.size(), vc
225:                        .size() == 2);
226:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0))
227:                        .elementAt(0)).getMethod().getSignature()));
228:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0))
229:                        .elementAt(2)).getMethod().getSignature()));
230:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1))
231:                        .elementAt(0)).getMethod().getSignature()));
232:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1))
233:                        .elementAt(2)).getMethod().getSignature()));
234:            }
235:
236:            public void testBreadthSearchSimple() {
237:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
238:                MethodMap mp = new MethodMap();
239:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
240:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
241:                MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
242:                MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
243:                MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
244:                mp.put(m1.getMethodKey(), m1);
245:                mp.put(m2.getMethodKey(), m2);
246:                mp.put(m3.getMethodKey(), m3);
247:                mp.put(m4.getMethodKey(), m4);
248:                mp.put(m5.getMethodKey(), m5);
249:
250:                a.setAllMethods(mp);
251:                a.put(m1.getMethodKey(), m2.getMethodKey());
252:                a.put(m2.getMethodKey(), m3.getMethodKey());
253:                a.put(m3.getMethodKey(), m4.getMethodKey());
254:                a.put(m3.getMethodKey(), m5.getMethodKey());
255:                Vector vc = a.getSearchMethod().extractTraceListForKey("A>>1");
256:                System.out.println("§ 237 " + vc);
257:                // § 229 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
258:                assertTrue(vc.size() == 2);
259:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0))
260:                        .elementAt(0)).getMethod().getSignature()));
261:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0))
262:                        .elementAt(2)).getMethod().getSignature()));
263:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1))
264:                        .elementAt(0)).getMethod().getSignature()));
265:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1))
266:                        .elementAt(2)).getMethod().getSignature()));
267:            }
268:
269:            public void testBreadthSearchWithMultipleStartingPoints() {
270:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
271:                MethodMap mp = new MethodMap();
272:                MethodWrapper m1a = new MethodWrapperDeclaration("1", "A");
273:                MethodWrapper m1b = new MethodWrapperDeclaration("1", "A");
274:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
275:                MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
276:                MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
277:                MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
278:                mp.put(m1a.getMethodKey(), m1a);
279:                mp.put(m1b.getMethodKey(), m1b);
280:                mp.put(m2.getMethodKey(), m2);
281:                mp.put(m3.getMethodKey(), m3);
282:                mp.put(m4.getMethodKey(), m4);
283:                mp.put(m5.getMethodKey(), m5);
284:
285:                a.setAllMethods(mp);
286:                a.put(m1a.getMethodKey(), m2.getMethodKey());
287:                a.put(m1b.getMethodKey(), m2.getMethodKey());
288:                a.put(m2.getMethodKey(), m3.getMethodKey());
289:                a.put(m3.getMethodKey(), m4.getMethodKey());
290:                a.put(m3.getMethodKey(), m5.getMethodKey());
291:                SearchMethod scm = a.getSearchMethod();
292:                Vector vc = scm.extractTraceListForKey("A>>1");
293:                System.out.println("§ 270 " + vc);
294:                // § 270 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2], [A>>1, A>>2, A>>3, A>>4]]
295:                assertTrue(vc.size() == 3);
296:            }
297:
298:            public void testBreadthSearchSimpleWithHashCode() {
299:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
300:                MethodMap mp = new MethodMap();
301:
302:                MethodWrapperDeclaration m1 = new MethodWrapperDeclaration("1",
303:                        "A");
304:                mp.put(m1.getMethodKey(), m1);
305:
306:                MethodWrapperDeclaration m2 = new MethodWrapperDeclaration("2",
307:                        "A");
308:                mp.put(m2.getMethodKey(), m2);
309:
310:                MethodWrapperDeclaration m3 = new MethodWrapperDeclaration("3",
311:                        "A");
312:                mp.put(m3.getMethodKey(), m3);
313:
314:                MethodWrapperDeclaration m4 = new MethodWrapperDeclaration("4",
315:                        "A");
316:                mp.put(m4.getMethodKey(), m4);
317:
318:                MethodWrapperDeclaration m5 = new MethodWrapperDeclaration("5",
319:                        "A");
320:                mp.put(m5.getMethodKey(), m5);
321:
322:                a.setAllMethods(mp);
323:                a.put(m1.getMethodKey(), m2.getMethodKey());
324:                a.put(m2.getMethodKey(), m3.getMethodKey());
325:                a.put(m3.getMethodKey(), m4.getMethodKey());
326:                a.put(m3.getMethodKey(), m5.getMethodKey());
327:
328:                SearchMethod sm = a.getSearchMethod();
329:                Vector vc = sm.extractTraceListForKey("A>>1");
330:                System.out.println("§ 306 Hash " + vc);
331:                // § 229 [[A>>1, A>>2, A>>3, A>>5], [A>>1, A>>2, A>>3, A>>4]]
332:                assertTrue(vc.size() == 2);
333:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(0))
334:                        .elementAt(0)).getMethod().getSignature()));
335:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(0))
336:                        .elementAt(2)).getMethod().getSignature()));
337:                assertTrue("1".equals(((TracedMethod) ((Trace) vc.elementAt(1))
338:                        .elementAt(0)).getMethod().getSignature()));
339:                assertTrue("3".equals(((TracedMethod) ((Trace) vc.elementAt(1))
340:                        .elementAt(2)).getMethod().getSignature()));
341:
342:            }
343:
344:            public void testBreadthSearchCommonEndpoint() {
345:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
346:                MethodMap mp = new MethodMap();
347:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
348:                mp.put(m1.getMethodKey(), m1);
349:
350:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
351:                mp.put(m2.getMethodKey(), m2);
352:
353:                MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
354:                mp.put(m3.getMethodKey(), m3);
355:
356:                MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
357:                mp.put(m4.getMethodKey(), m4);
358:
359:                MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
360:                mp.put(m5.getMethodKey(), m5);
361:
362:                MethodWrapper m6 = new MethodWrapperDeclaration("6", "A");
363:                mp.put(m6.getMethodKey(), m6);
364:
365:                MethodWrapper m7 = new MethodWrapperDeclaration("7", "A");
366:                mp.put(m7.getMethodKey(), m7);
367:
368:                MethodWrapper m8 = new MethodWrapperDeclaration("8", "A");
369:                mp.put(m8.getMethodKey(), m8);
370:
371:                a.setAllMethods(mp);
372:
373:                a.put(m1.getMethodKey(), m2.getMethodKey());
374:                a.put(m2.getMethodKey(), m3.getMethodKey());
375:                a.put(m3.getMethodKey(), m8.getMethodKey());
376:
377:                a.put(m1.getMethodKey(), m5.getMethodKey());
378:                a.put(m1.getMethodKey(), m6.getMethodKey());
379:                a.put(m6.getMethodKey(), m7.getMethodKey());
380:                a.put(m7.getMethodKey(), m8.getMethodKey());
381:
382:                Vector vc = a.getSearchMethod().extractTraceListForKey("A>>1");
383:                System.out.println("§ 356 " + vc);
384:                assertTrue(vc.size() == 3);
385:
386:                // § 296 [[A>>1, A>>6, A>>7, A>>8], [A>>1, A>>5], [A>>1, A>>2, A>>3, A>>8]]
387:                // § 331 [[A>>1, A>>2, A>>3, A>>8], [A>>1, A>>6, A>>7, A>>8], [A>>1, A>>5]]
388:                // § 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]]
389:
390:                int sum1 = ((Trace) vc.elementAt(0)).size();
391:                int sum2 = ((Trace) vc.elementAt(1)).size();
392:                int sum3 = ((Trace) vc.elementAt(2)).size();
393:                assertTrue(10 == (sum1 + sum2 + sum3));
394:                /*
395:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
396:                assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(3)).getMethod().getSignature()));
397:
398:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
399:                assertTrue("5".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(1)).getMethod().getSignature()));
400:
401:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(0)).getMethod().getSignature()));
402:                assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(3)).getMethod().getSignature()));
403:                 */
404:            }
405:
406:            //!! non intuitive traversal order
407:            public void testBreadthSearchCommonMiddlepoint() {
408:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
409:                MethodMap mp = new MethodMap();
410:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
411:                mp.put(m1.getMethodKey(), m1);
412:
413:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
414:                mp.put(m2.getMethodKey(), m2);
415:
416:                MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
417:                mp.put(m3.getMethodKey(), m3);
418:
419:                MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
420:                mp.put(m4.getMethodKey(), m4);
421:
422:                MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
423:                mp.put(m5.getMethodKey(), m5);
424:
425:                MethodWrapper m6 = new MethodWrapperDeclaration("6", "A");
426:                mp.put(m6.getMethodKey(), m6);
427:
428:                MethodWrapper m7 = new MethodWrapperDeclaration("7", "A");
429:                mp.put(m7.getMethodKey(), m7);
430:
431:                MethodWrapper m8 = new MethodWrapperDeclaration("8", "A");
432:                mp.put(m8.getMethodKey(), m8);
433:
434:                a.setAllMethods(mp);
435:
436:                // [A>>1, A>>2, A>>3, A>>8
437:                a.put(m1.getMethodKey(), m2.getMethodKey());
438:                a.put(m2.getMethodKey(), m3.getMethodKey());
439:                a.put(m3.getMethodKey(), m8.getMethodKey());
440:
441:                // [A>>1, A>>5]
442:                a.put(m1.getMethodKey(), m5.getMethodKey());
443:
444:                // [A>>1, A>>6,  A>>3, A>>7, A>>8]
445:                a.put(m1.getMethodKey(), m6.getMethodKey());
446:                a.put(m6.getMethodKey(), m3.getMethodKey());
447:                a.put(m3.getMethodKey(), m7.getMethodKey());
448:                a.put(m7.getMethodKey(), m8.getMethodKey());
449:
450:                SearchMethod sm = a.getSearchMethod();
451:                Vector vc = sm.extractTraceListForKey("A>>1");
452:                System.out.println("§ 419 " + vc);
453:                // § 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]]
454:                // § 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]]
455:                // § 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]]
456:                // § 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]]
457:                // § 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]]
458:                // § 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]]
459:                assertTrue(vc.size() == 4);
460:
461:                int sum1 = ((Trace) vc.elementAt(0)).size();
462:                int sum2 = ((Trace) vc.elementAt(1)).size();
463:                int sum3 = ((Trace) vc.elementAt(2)).size();
464:                int sum4 = ((Trace) vc.elementAt(3)).size();
465:
466:                assertTrue("total sum of traced methods should be 14 but is "
467:                        + (sum1 + sum2 + sum3 + sum4), 14 == (sum1 + sum2
468:                        + sum3 + sum4));
469:
470:                /*
471:                assertTrue( ((Trace)vc.elementAt(0)).size() == 2);
472:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(0)).getMethod().getSignature()));
473:                assertTrue("5".equals(((TracedMethod) ((Trace)vc.elementAt(0)).elementAt(1)).getMethod().getSignature()));
474:
475:                assertTrue( ((Trace)vc.elementAt(1)).size() == 5);
476:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(0)).getMethod().getSignature()));
477:                assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(1)).elementAt(4)).getMethod().getSignature()));
478:
479:                assertTrue( ((Trace)vc.elementAt(2)).size() == 3);
480:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(0)).getMethod().getSignature()));
481:                assertTrue("3".equals(((TracedMethod) ((Trace)vc.elementAt(2)).elementAt(2)).getMethod().getSignature()));
482:
483:                assertTrue( ((Trace)vc.elementAt(3)).size() == 4);
484:                assertTrue("1".equals(((TracedMethod) ((Trace)vc.elementAt(3)).elementAt(0)).getMethod().getSignature()));
485:                assertTrue("8".equals(((TracedMethod) ((Trace)vc.elementAt(3)).elementAt(3)).getMethod().getSignature()));
486:                 */
487:            }
488:
489:            public void testBreadthSearchSpider() {
490:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
491:                MethodMap mp = new MethodMap();
492:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
493:                mp.put(m1.getMethodKey(), m1);
494:
495:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
496:                mp.put(m2.getMethodKey(), m2);
497:                MethodWrapper m21 = new MethodWrapperDeclaration("2", "A");
498:                mp.put(m21.getMethodKey(), m21);
499:
500:                MethodWrapper m3 = new MethodWrapperDeclaration("3", "A");
501:                mp.put(m3.getMethodKey(), m3);
502:
503:                MethodWrapper m4 = new MethodWrapperDeclaration("4", "A");
504:                mp.put(m4.getMethodKey(), m4);
505:
506:                MethodWrapper m5 = new MethodWrapperDeclaration("5", "A");
507:                mp.put(m5.getMethodKey(), m5);
508:
509:                a.setAllMethods(mp);
510:
511:                a.put(m1.getMethodKey(), m2.getMethodKey());
512:
513:                a.put(m1.getMethodKey(), m21.getMethodKey());
514:
515:                a.put(m1.getMethodKey(), m3.getMethodKey());
516:
517:                a.put(m1.getMethodKey(), m4.getMethodKey());
518:                a.put(m4.getMethodKey(), m5.getMethodKey());
519:
520:                SearchMethod sm = a.getSearchMethod();
521:                Vector vc = sm.extractTraceListForKey("A>>1");
522:                System.out.println("§ 502 " + vc);
523:                // § 502 [[A>>1, A>>2], [A>>1, A>>2], [A>>1, A>>3], [A>>1, A>>4, A>>5]]
524:                // § 502 [[A>>1, A>>2], [A>>1, A>>2], [A>>1, A>>3], [A>>1, A>>4, A>>5]]
525:
526:                assertTrue(vc.size() == 4);
527:            }
528:
529:            public void testBreadthSearchSimpleDoubleEdge() {
530:
531:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
532:                MethodMap mp = new MethodMap();
533:
534:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
535:                mp.put(m1.getMethodKey(), m1);
536:
537:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
538:                mp.put(m2.getMethodKey(), m2);
539:
540:                a.setAllMethods(mp);
541:                a.put(m1.getMethodKey(), m2.getMethodKey());
542:                //	a.put(m1.getMethodKey(), m2.getMethodKey());
543:                //	a.put(m1.getMethodKey(), m2.getMethodKey());
544:
545:                SearchMethod sm = a.getSearchMethod();
546:                Vector vc = sm.extractTraceListForKey("A>>1");
547:                System.out.println("§ 515 " + vc);
548:
549:                // § 515 [[A>>1, A>>2]
550:                assertTrue(vc.size() == 1);
551:            }
552:
553:            public void testBreadthSearchSimpleDoubleEdgeDoubleNode() {
554:
555:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
556:                MethodMap mp = new MethodMap();
557:
558:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
559:                mp.put(m1.getMethodKey(), m1);
560:
561:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
562:                mp.put(m2.getMethodKey(), m2);
563:
564:                MethodWrapper m3 = new MethodWrapperDeclaration("1", "A");
565:                mp.put(m3.getMethodKey(), m3);
566:
567:                MethodWrapper m4 = new MethodWrapperDeclaration("2", "A");
568:                mp.put(m4.getMethodKey(), m4);
569:
570:                a.setAllMethods(mp);
571:                a.put(m1.getMethodKey(), m2.getMethodKey());
572:                a.put(m3.getMethodKey(), m4.getMethodKey());
573:
574:                SearchMethod sm = a.getSearchMethod();
575:                Vector vc = sm.extractTraceListForKey("A>>1");
576:                System.out.println("§ 546 " + vc);
577:
578:                // § 546 [[A>>1, A>>2], [A>>1, A>>2]]
579:                assertTrue(vc.size() == 2);
580:            }
581:
582:            public void testBreadthSearchSimpleDoubleEdgeDoubleNodeAndSomething() {
583:
584:                AdjacencyMatrix a = new AdjacencyMatrix(new BreadthSearch());
585:                MethodMap mp = new MethodMap();
586:
587:                MethodWrapper m1 = new MethodWrapperDeclaration("1", "A");
588:                mp.put(m1.getMethodKey(), m1);
589:
590:                MethodWrapper m2 = new MethodWrapperDeclaration("2", "A");
591:                mp.put(m2.getMethodKey(), m2);
592:
593:                MethodWrapper m3 = new MethodWrapperDeclaration("1", "A");
594:                mp.put(m3.getMethodKey(), m3);
595:
596:                MethodWrapper m4 = new MethodWrapperDeclaration("2", "A");
597:                mp.put(m4.getMethodKey(), m4);
598:
599:                MethodWrapper m5 = new MethodWrapperDeclaration("3", "A");
600:                mp.put(m5.getMethodKey(), m5);
601:
602:                a.setAllMethods(mp);
603:                a.put(m1.getMethodKey(), m2.getMethodKey());
604:                a.put(m3.getMethodKey(), m4.getMethodKey());
605:                a.put(m4.getMethodKey(), m5.getMethodKey());
606:
607:                SearchMethod sm = a.getSearchMethod();
608:                Vector vc = sm.extractTraceListForKey("A>>1");
609:                System.out.println("§ 581 " + vc);
610:
611:                // § 581 [[A>>1, A>>2], [A>>1, A>>2, A>>3]]
612:                assertTrue(vc.size() == 2);
613:            }
614:
615:            public void testBoolean() {
616:                Boolean ret = new Boolean(false);
617:                assertTrue(!ret.booleanValue());
618:                ret = new Boolean(true);
619:                assertTrue(ret.booleanValue());
620:            }
621:
622:            public void testCloneTrace() {
623:
624:                Trace t = new Trace();
625:                for (int i = 0; i < 3; i++) {
626:
627:                    MethodWrapperDeclaration m = new MethodWrapperDeclaration(
628:                            "lala" + i, "A");
629:
630:                    TracedMethod tm = new TracedMethod(m);
631:                    tm.setMethod(m);
632:                    t.add(tm);
633:                }
634:                Trace cloneTrace = (Trace) t.clone();
635:                assertTrue(cloneTrace.equals(t));
636:            }
637:
638:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.