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