001 /* 002 * Created on Dec 4, 2004 003 * 004 */ 005 package aima.test.logictest.prop.visitors; 006 007 import java.util.Set; 008 009 import junit.framework.TestCase; 010 import aima.logic.propositional.parsing.PEParser; 011 import aima.logic.propositional.parsing.ast.Sentence; 012 import aima.logic.propositional.visitors.SymbolCollector; 013 014 /** 015 * @author Ravi Mohan 016 * 017 */ 018 019 public class SymbolCollectorTest extends TestCase { 020 private PEParser parser; 021 022 private SymbolCollector collector; 023 024 @Override 025 public void setUp() { 026 parser = new PEParser(); 027 collector = new SymbolCollector(); 028 } 029 030 public void testCollectSymbolsFromComplexSentence() { 031 Sentence sentence = (Sentence) parser 032 .parse(" ( ( ( NOT B11 ) OR ( P12 OR P21 ) ) AND ( ( B11 OR ( NOT P12 ) ) AND ( B11 OR ( NOT P21 ) ) ) )"); 033 Set s = collector.getSymbolsIn(sentence); 034 assertEquals(3, s.size()); 035 Sentence b11 = (Sentence) parser.parse("B11"); 036 Sentence p21 = (Sentence) parser.parse("P21"); 037 Sentence p12 = (Sentence) parser.parse("P12"); 038 assertTrue(s.contains(b11)); 039 assertTrue(s.contains(p21)); 040 assertTrue(s.contains(p12)); 041 042 } 043 044 }