Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1a4b2d

Browse files
committed
Add test for TableDrivenAgentProgram.
1 parent 9ccc092 commit e1a4b2d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
3535
| 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included |
3636
| 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included |
3737
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | | Included |
38-
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | Included |
38+
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | Done | Included |
3939
| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included |
4040
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included |
4141
| 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included |

tests/test_agents.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from agents import Direction
33
from agents import Agent
44
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
5-
RandomVacuumAgent
5+
RandomVacuumAgent, TableDrivenAgentProgram
66

77

88
random.seed("aima-python")
@@ -111,6 +111,20 @@ def test_compare_agents() :
111111
assert performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent
112112

113113

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+
114128
def test_Agent():
115129
def constant_prog(percept):
116130
return percept

0 commit comments

Comments
 (0)