001    /*
002     * Created on Dec 3, 2004
003     *
004     */
005    package aima.test.logictest.prop.algorithms;
006    
007    import junit.framework.TestCase;
008    import aima.logic.propositional.algorithms.KnowledgeBase;
009    
010    /**
011     * @author Ravi Mohan
012     * 
013     */
014    
015    public class KnowledgeBaseTest extends TestCase {
016            private KnowledgeBase kb;
017    
018            @Override
019            public void setUp() {
020                    kb = new KnowledgeBase();
021            }
022    
023            public void testTellInsertsSentence() {
024                    kb.tell("(A AND B)");
025                    assertEquals(1, kb.size());
026            }
027    
028            public void testTellDoesNotInsertSameSentenceTwice() {
029                    kb.tell("(A AND B)");
030                    assertEquals(1, kb.size());
031                    kb.tell("(A AND B)");
032                    assertEquals(1, kb.size());
033            }
034    
035            public void testEmptyKnowledgeBaseIsAnEmptyString() {
036                    assertEquals("", kb.toString());
037            }
038    
039            public void testKnowledgeBaseWithOneSentenceToString() {
040                    kb.tell("(A AND B)");
041                    assertEquals(" ( A AND B )", kb.toString());
042            }
043    
044            public void testKnowledgeBaseWithTwoSentencesToString() {
045                    kb.tell("(A AND B)");
046                    kb.tell("(C AND D)");
047                    assertEquals(" (  ( A AND B ) AND  ( C AND D ) )", kb.toString());
048            }
049    
050            public void testKnowledgeBaseWithThreeSentencesToString() {
051                    kb.tell("(A AND B)");
052                    kb.tell("(C AND D)");
053                    kb.tell("(E AND F)");
054                    assertEquals(
055                                    " (  (  ( A AND B ) AND  ( C AND D ) ) AND  ( E AND F ) )", kb
056                                                    .toString());
057            }
058    }