ContextFreeGrammar extends Grammar { void setProductionMinimumDepth(Rule r) { Iterator<Production> pIt; Iterator<Symbol> sIt; Symbol sym; Production prod; Rule rule; int minDepth; pIt = r.iterator(); while(pIt.hasNext()) { minDepth = 0; prod = pIt.next(); sIt = prod.iterator(); while(sIt.hasNext()) { sym = sIt.next(); if(sym.getType() == Enums.SymbolType.NTSymbol) { rule = this.findRule(sym); if(rule!=null) { if(rule.getMinimumDepth() > minDepth) { minDepth = rule.getMinimumDepth(); } } } } prod.setMinimumDepth(minDepth); } } ContextFreeGrammar();   ContextFreeGrammar(ContextFreeGrammar g); abstract boolean genotype2Phenotype(); abstract boolean phenotype2Genotype(); abstract int getUsedCodons(); abstract int getUsedWraps(); @SuppressWarnings({"UnusedReturnValue", "IOResourceOpenedButNotSafelyClosed"}) boolean readBNFFile(String file_name); Rule findRule(Symbol s); Rule findRule(String s); ArrayList getTerminalRules(); ArrayList getNonTerminalRules();  }
@Test public void testSetProductionMinimumDepth() { System.out.println("* ContextFreeGrammarTest: setProductionMinimumDepth"); Rule r = g.getRules().get(0); g.setProductionMinimumDepth(r); assertEquals(2, r.get(0).getMinimumDepth()); assertEquals(3, r.get(1).getMinimumDepth()); r = g.getRules().get(2); g.setProductionMinimumDepth(r); assertEquals(0, r.get(0).getMinimumDepth()); try { g.setProductionMinimumDepth(null); } catch (NullPointerException e) { assertTrue(true); } assertEquals(1, g.getRules().get(1).get(0).getMinimumDepth()); }