|
2 | 2 | from agents import Direction
|
3 | 3 | from agents import Agent
|
4 | 4 | from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
|
5 |
| - RandomVacuumAgent |
| 5 | + RandomVacuumAgent, TableDrivenAgentProgram |
6 | 6 |
|
7 | 7 |
|
8 | 8 | random.seed("aima-python")
|
@@ -111,6 +111,20 @@ def test_compare_agents() :
|
111 | 111 | assert performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent
|
112 | 112 |
|
113 | 113 |
|
| 114 | +def test_TableDrivenAgentProgram(): |
| 115 | + table = {(('foo', 1),): 'action1', |
| 116 | + (('foo', 2),): 'action2', |
| 117 | + (('bar', 1),): 'action3', |
| 118 | + (('bar', 2),): 'action1', |
| 119 | + (('foo', 1), ('foo', 1),): 'action2', |
| 120 | + (('foo', 1), ('foo', 2),): 'action3', |
| 121 | + } |
| 122 | + agent_program = TableDrivenAgentProgram(table) |
| 123 | + assert agent_program(('foo', 1)) == 'action1' |
| 124 | + assert agent_program(('foo', 2)) == 'action3' |
| 125 | + assert agent_program(('invalid percept',)) == None |
| 126 | + |
| 127 | + |
114 | 128 | def test_Agent():
|
115 | 129 | def constant_prog(percept):
|
116 | 130 | return percept
|
|
0 commit comments