001    /*
002     * Created on Aug 1, 2005
003     *
004     */
005    package aima.test.learningtest;
006    
007    import java.util.List;
008    
009    import junit.framework.TestCase;
010    import aima.learning.framework.DataSet;
011    import aima.learning.framework.DataSetFactory;
012    import aima.learning.framework.Example;
013    import aima.learning.inductive.DLTest;
014    import aima.learning.inductive.DLTestFactory;
015    
016    /**
017     * @author Ravi Mohan
018     * 
019     */
020    
021    public class DLTestTestCase extends TestCase {
022            public void testDecisionList() throws Exception {
023                    DataSet ds = DataSetFactory.getRestaurantDataSet();
024                    List<DLTest> dlTests = new DLTestFactory()
025                                    .createDLTestsWithAttributeCount(ds, 1);
026                    assertEquals(26, dlTests.size());
027            }
028    
029            public void testDLTestMatchSucceedsWithMatchedExample() throws Exception {
030                    DataSet ds = DataSetFactory.getRestaurantDataSet();
031                    Example e = ds.getExample(0);
032                    DLTest test = new DLTest();
033                    test.add("type", "French");
034                    assertTrue(test.matches(e));
035            }
036    
037            public void testDLTestMatchFailsOnMismatchedExample() throws Exception {
038                    DataSet ds = DataSetFactory.getRestaurantDataSet();
039                    Example e = ds.getExample(0);
040                    DLTest test = new DLTest();
041                    test.add("type", "Thai");
042                    assertFalse(test.matches(e));
043            }
044    
045            public void testDLTestMatchesEvenOnMismatchedTargetAttributeValue()
046                            throws Exception {
047                    DataSet ds = DataSetFactory.getRestaurantDataSet();
048                    Example e = ds.getExample(0);
049                    DLTest test = new DLTest();
050                    test.add("type", "French");
051                    assertTrue(test.matches(e));
052            }
053    
054            public void testDLTestReturnsMatchedAndUnmatchedExamplesCorrectly()
055                            throws Exception {
056                    DataSet ds = DataSetFactory.getRestaurantDataSet();
057                    DLTest test = new DLTest();
058                    test.add("type", "Burger");
059    
060                    DataSet matched = test.matchedExamples(ds);
061                    assertEquals(4, matched.size());
062    
063                    DataSet unmatched = test.unmatchedExamples(ds);
064                    assertEquals(8, unmatched.size());
065            }
066    
067    }