001    package aima.test.tvenvironmenttest;
002    
003    import java.util.Hashtable;
004    import java.util.Map;
005    
006    import junit.framework.TestCase;
007    import aima.basic.Agent;
008    import aima.basic.AgentProgram;
009    import aima.basic.Percept;
010    import aima.basic.PerceptSequence;
011    import aima.basic.vaccum.TableDrivenAgentProgram;
012    
013    /**
014     * @author Ciaran O'Reilly
015     * 
016     */
017    
018    public class TableDrivenAgentProgramTest extends TestCase {
019    
020            private Agent agent;
021    
022            @Override
023            public void setUp() {
024                    Map<PerceptSequence, String> perceptSequenceActions = new Hashtable<PerceptSequence, String>();
025                    perceptSequenceActions.put(new PerceptSequence(new Percept("key1",
026                                    "value1")), "action1");
027                    perceptSequenceActions.put(new PerceptSequence(new Percept("key1",
028                                    "value1"), new Percept("key1", "value2")), "action2");
029                    perceptSequenceActions.put(new PerceptSequence(new Percept("key1",
030                                    "value1"), new Percept("key1", "value2"), new Percept("key1",
031                                    "value3")), "action3");
032    
033                    agent = new TestAgent(new TableDrivenAgentProgram(
034                                    perceptSequenceActions));
035            }
036    
037            public void testExistingSequences() {
038                    assertEquals("action1", agent.execute(new Percept("key1", "value1")));
039                    assertEquals("action2", agent.execute(new Percept("key1", "value2")));
040                    assertEquals("action3", agent.execute(new Percept("key1", "value3")));
041            }
042    
043            public void testNonExistingSequence() {
044                    assertEquals("action1", agent.execute(new Percept("key1", "value1")));
045                    assertEquals("NoOP", agent.execute(new Percept("key1", "value3")));
046            }
047    }
048    
049    class TestAgent extends Agent {
050            public TestAgent(AgentProgram agent) {
051                    super(agent);
052            }
053    }