001    /*
002     * Created on Aug 30, 2003 by Ravi Mohan
003     *
004     */
005    package aima.test.logictest.prop.parser;
006    
007    import junit.framework.TestCase;
008    import aima.logic.common.LogicTokenTypes;
009    import aima.logic.common.Token;
010    import aima.logic.propositional.parsing.PELexer;
011    
012    /**
013     * @author Ravi Mohan
014     * 
015     */
016    public class PELexerTest extends TestCase {
017            public void testLexBasicExpression() {
018                    PELexer pelexer = new PELexer();
019                    pelexer.setInput("(P)");
020                    assertEquals(new Token(LogicTokenTypes.LPAREN, "("), pelexer
021                                    .nextToken());
022                    assertEquals(new Token(LogicTokenTypes.SYMBOL, "P"), pelexer
023                                    .nextToken());
024                    assertEquals(new Token(LogicTokenTypes.RPAREN, ")"), pelexer
025                                    .nextToken());
026    
027                    assertEquals(new Token(LogicTokenTypes.EOI, "EOI"), pelexer.nextToken());
028            }
029    
030            public void testLexNotExpression() {
031                    PELexer pelexer = new PELexer();
032                    pelexer.setInput("(NOT P)");
033                    assertEquals(new Token(LogicTokenTypes.LPAREN, "("), pelexer
034                                    .nextToken());
035                    assertEquals(new Token(LogicTokenTypes.CONNECTOR, "NOT"), pelexer
036                                    .nextToken());
037    
038                    assertEquals(new Token(LogicTokenTypes.SYMBOL, "P"), pelexer
039                                    .nextToken());
040                    assertEquals(new Token(LogicTokenTypes.RPAREN, ")"), pelexer
041                                    .nextToken());
042    
043                    assertEquals(new Token(LogicTokenTypes.EOI, "EOI"), pelexer.nextToken());
044            }
045    
046            public void testLexImpliesExpression() {
047                    PELexer pelexer = new PELexer();
048                    pelexer.setInput("(P => Q)");
049                    assertEquals(new Token(LogicTokenTypes.LPAREN, "("), pelexer
050                                    .nextToken());
051                    assertEquals(new Token(LogicTokenTypes.SYMBOL, "P"), pelexer
052                                    .nextToken());
053                    assertEquals(new Token(LogicTokenTypes.CONNECTOR, "=>"), pelexer
054                                    .nextToken());
055            }
056    
057            public void testLexBiCOnditionalExpression() {
058                    PELexer pelexer = new PELexer();
059                    pelexer.setInput("(B11 <=> (P12 OR P21))");
060                    assertEquals(new Token(LogicTokenTypes.LPAREN, "("), pelexer
061                                    .nextToken());
062                    assertEquals(new Token(LogicTokenTypes.SYMBOL, "B11"), pelexer
063                                    .nextToken());
064                    assertEquals(new Token(LogicTokenTypes.CONNECTOR, "<=>"), pelexer
065                                    .nextToken());
066            }
067    }