Exemplo n.º 1
0
  @Test
  public void testMore() throws InterruptedException {
    final Element e1 = TestUtils.getElement("test1", Regexp.<AbstractStructuralNode>getMutable());
    final Element e2 = TestUtils.getElement("test2", Regexp.<AbstractStructuralNode>getMutable());
    final Element e3 = TestUtils.getElement("test3", Regexp.<AbstractStructuralNode>getMutable());
    final Element e4 = TestUtils.getElement("test4", Regexp.<AbstractStructuralNode>getMutable());

    e1.getSubnodes().setType(RegexpType.CONCATENATION);
    e1.getSubnodes().setInterval(RegexpInterval.getOnce());
    e2.getSubnodes().setType(RegexpType.CONCATENATION);
    e2.getSubnodes().setInterval(RegexpInterval.getOnce());
    e3.getSubnodes().setType(RegexpType.CONCATENATION);
    e3.getSubnodes().setInterval(RegexpInterval.getOnce());
    e4.getSubnodes().setType(RegexpType.CONCATENATION);
    e4.getSubnodes().setInterval(RegexpInterval.getOnce());

    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e2));
    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e3));
    e3.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e4));

    final List<Element> elements = Arrays.asList(e1, e2);

    Collections.shuffle(elements);

    final TopologicalSort s = new TopologicalSort(elements);
    final List<Element> toposorted = s.sort();

    assertEquals(2, toposorted.size());
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e2));
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e3));
    assertTrue(toposorted.indexOf(e2) > toposorted.indexOf(e4));
  }
  /** Test of cleanRegularExpression method, of class CleanerEmptyChildren. */
  @Test
  public void testCleanRegularExpression2() {
    System.out.println("cleanRegularExpression2");

    final Regexp<String> r3 = Regexp.<String>getMutable();
    r3.setInterval(RegexpInterval.getOnce());
    r3.setType(RegexpType.TOKEN);
    r3.setContent("a");
    r3.setImmutable();

    final Regexp<String> r2 = Regexp.<String>getMutable();
    r2.setInterval(RegexpInterval.getOnce());
    r2.setType(RegexpType.CONCATENATION);
    r2.addChild(r3);
    r2.setImmutable();

    final Regexp<String> r1 = Regexp.<String>getMutable();
    r1.setInterval(RegexpInterval.getOnce());
    r1.setType(RegexpType.CONCATENATION);
    r1.addChild(r2);
    r1.setImmutable();

    final Regexp<String> regexp = r1;
    final EmptyChildren<String> instance = new EmptyChildren<String>();
    final Regexp<String> result = instance.cleanRegularExpression(regexp);
    assertEquals("a", result.toString());
  }
Exemplo n.º 3
0
 @Test
 public void testOne() throws InterruptedException {
   final Element e = TestUtils.getElement("test", Regexp.<AbstractStructuralNode>getMutable());
   e.getSubnodes().setType(RegexpType.CONCATENATION);
   e.getSubnodes().setInterval(RegexpInterval.getOnce());
   final TopologicalSort s = new TopologicalSort(Arrays.asList(e));
   final List<Element> elements = s.sort();
   assertEquals(1, elements.size());
   assertEquals(e, elements.get(0));
 }