Skip to content

Commit c5497aa

Browse files
committed
Added test for SimpleReflexAgentProgram
1 parent 1ba1aed commit c5497aa

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

tests/test_agents.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from agents import Direction
33
from agents import Agent
44
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
5-
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram
5+
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \
6+
SimpleReflexAgentProgram, rule_match
67

78

89
random.seed("aima-python")
@@ -156,6 +157,38 @@ def test_TableDrivenVacuumAgent() :
156157
environment.run()
157158
# check final status of the environment
158159
assert environment.status == {(1, 0):'Clean', (0, 0):'Clean'}
160+
161+
def test_SimpleReflexAgentProgram():
162+
class Rule:
163+
164+
def __init__(self, state, action):
165+
self.__state = state
166+
self.action = action
167+
168+
def matches(self, state):
169+
return self.__state == state
170+
171+
loc_A = (0, 0)
172+
loc_B = (1, 0)
173+
174+
# create rules for a two state Vacuum Environment
175+
rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"),
176+
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
177+
178+
def interpret_input(state):
179+
return state
180+
181+
# create an program and then an object of the SimpleReflexAgentProgram
182+
program = SimpleReflexAgentProgram(rules, interpret_input)
183+
agent = Agent(program)
184+
# create an object of TrivialVacuumEnvironment
185+
environment = TrivialVacuumEnvironment()
186+
# add agent to the environment
187+
environment.add_thing(agent)
188+
# run the environment
189+
environment.run()
190+
# check final status of the environment
191+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
159192

160193

161194
def test_compare_agents() :
@@ -181,3 +214,18 @@ def constant_prog(percept):
181214
agent = Agent(constant_prog)
182215
result = agent.program(5)
183216
assert result == 5
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+

0 commit comments

Comments
 (0)