Skip to content

Commit 0cd0612

Browse files
nouman-10antmarakis
authored andcommitted
Added test for SimpleReflexAgentProgram (#808)
* Added test for simpleReflexAgent * Fixed a bug * Fixed another bug
1 parent c908058 commit 0cd0612

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
6363
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included |
6464
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | Done | Included |
6565
| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included |
66-
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included |
66+
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | Done | Included |
6767
| 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included |
6868
| 3 | Problem | `Problem` | [`search.py`][search] | Done | Included |
6969
| 3 | Node | `Node` | [`search.py`][search] | Done | Included |

tests/test_agents.py

Lines changed: 34 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")
@@ -131,6 +132,38 @@ def test_ReflexVacuumAgent() :
131132
# check final status of the environment
132133
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
133134

135+
def test_SimpleReflexAgentProgram():
136+
class Rule:
137+
138+
def __init__(self, state, action):
139+
self.__state = state
140+
self.action = action
141+
142+
def matches(self, state):
143+
return self.__state == state
144+
145+
loc_A = (0, 0)
146+
loc_B = (1, 0)
147+
148+
# create rules for a two state Vacuum Environment
149+
rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"),
150+
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
151+
152+
def interpret_input(state):
153+
return state
154+
155+
# create a program and then an object of the SimpleReflexAgentProgram
156+
program = SimpleReflexAgentProgram(rules, interpret_input)
157+
agent = Agent(program)
158+
# create an object of TrivialVacuumEnvironment
159+
environment = TrivialVacuumEnvironment()
160+
# add agent to the environment
161+
environment.add_thing(agent)
162+
# run the environment
163+
environment.run()
164+
# check final status of the environment
165+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
166+
134167

135168
def test_ModelBasedVacuumAgent() :
136169
# create an object of the ModelBasedVacuumAgent

0 commit comments

Comments
 (0)