KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > parser > DGUtilsTest


1 /*
2  * DGUtilsTest.java
3  * JUnit based test
4  *
5  * Created on February 1, 2006, 2:18 PM
6  */

7
8 package org.netbeans.modules.languages.parser;
9
10 import java.util.Collections JavaDoc;
11 import junit.framework.*;
12
13
14 /**
15  *
16  * @author Jan Jancura
17  */

18 public class DGUtilsTest extends TestCase {
19     
20     public DGUtilsTest (String JavaDoc testName) {
21         super (testName);
22     }
23
24
25     public void testReduce () {
26         DG dg = DG.createDG (new Integer JavaDoc (1));
27         dg.addNode (new Integer JavaDoc (2));
28         dg.addNode (new Integer JavaDoc (3));
29         dg.addNode (new Integer JavaDoc (4));
30         dg.addEdge (new Integer JavaDoc (1), new Integer JavaDoc (2), new Character JavaDoc ('a'));
31         dg.addEdge (new Integer JavaDoc (2), new Integer JavaDoc (3), new Character JavaDoc ('b'));
32         dg.addEdge (new Integer JavaDoc (3), new Integer JavaDoc (4), new Character JavaDoc ('a'));
33         dg.addEdge (new Integer JavaDoc (4), new Integer JavaDoc (3), new Character JavaDoc ('b'));
34         dg.setStart (new Integer JavaDoc (1));
35         dg.setEnds (Collections.singleton (new Integer JavaDoc (3)));
36         
37         dg.setProperty (new Integer JavaDoc (1), "jedna", null);
38         dg.setProperty (new Integer JavaDoc (2), "dve", null);
39         dg.setProperty (new Integer JavaDoc (3), "tri", null);
40         dg.setProperty (new Integer JavaDoc (4), "ctyri", null);
41         dg.setProperty (new Integer JavaDoc (1), new Character JavaDoc ('a'), "jedna a", null);
42         dg.setProperty (new Integer JavaDoc (2), new Character JavaDoc ('b'), "dve b", null);
43         dg.setProperty (new Integer JavaDoc (3), new Character JavaDoc ('a'), "tri a", null);
44         dg.setProperty (new Integer JavaDoc (4), new Character JavaDoc ('b'), "ctyri b", null);
45         dg = DGUtils.reduce (dg, nodeFactory);
46         
47         assertEquals (new Integer JavaDoc (1), dg.getStartNode ());
48         assertEquals (Collections.singleton (new Integer JavaDoc (3)), dg.getEnds ());
49         assertEquals (3, dg.getNodes ().size ());
50         
51     }
52     
53     private NodeFactory nodeFactory = new NodeFactory<Integer JavaDoc> () {
54         public Integer JavaDoc createNode() {
55             return Integer.valueOf (counter++);
56         }
57
58         private int counter = 1;
59     };
60 }
61
Popular Tags