コード例 #1
0
  @Test
  public void testContainsOneNonTerminal() {
    Production production = new Production(new Symbol(), 2);

    assertFalse("null list", production.containsOneNonTerminal());

    production.setHandle(new SymbolList());
    assertFalse("empty list", production.containsOneNonTerminal());

    production.getHandle().clear();
    production.getHandle().add(new Symbol("Symbol1", SymbolType.NOISE, 1));
    assertFalse("one terminal symbol", production.containsOneNonTerminal());

    production.getHandle().clear();
    production.getHandle().add(new Symbol("Symbol1", SymbolType.NON_TERMINAL, 1));
    assertTrue("one non-terminal", production.containsOneNonTerminal());

    production.getHandle().add(new Symbol("Symbol2", SymbolType.NON_TERMINAL, 2));
    assertFalse("two non-terminals", production.containsOneNonTerminal());

    production.getHandle().clear();
    production.getHandle().add(new Symbol("Symbol1", SymbolType.NON_TERMINAL, 1));
    assertTrue("one non-terminal", production.containsOneNonTerminal());
    production.getHandle().add(new Symbol("Symbol2", SymbolType.NOISE, 2));
    assertFalse("one terminal/one non-terminal", production.containsOneNonTerminal());
  }
コード例 #2
0
 @Test
 public void testConstructor() {
   Symbol symbol = new Symbol("Symbol1", SymbolType.CONTENT, 2);
   Production production = new Production(symbol, 7);
   assertEquals("head", symbol, production.getHead());
   assertEquals("handle", 0, production.getHandle().size());
   assertEquals("index", 7, production.getTableIndex());
 }
コード例 #3
0
  @Test
  public void testSetters() {
    Symbol symbol = new Symbol("Symbol1", SymbolType.CONTENT, 2);
    Production production = new Production(symbol, 7);

    // Setting to null creates a new, empty list
    production.setHandle(null);
    assertNotNull("handle", production.getHandle());

    Symbol newSymbol = new Symbol("Symbol2", SymbolType.CONTENT, 2);
    production.setHead(newSymbol);

    SymbolList newList = new SymbolList(3);
    production.setHandle(newList);

    production.setTableIndex(44);

    assertEquals("head", newSymbol, production.getHead());
    assertEquals("handle", newList, production.getHandle());
    assertEquals("handle size", 3, production.getHandle().size());
    assertEquals("index", 44, production.getTableIndex());
  }