Skip to content

Added Tests for Simple-Reflex-Agent #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included |
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | Done | Included |
| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included |
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included |
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | Done | Included |
| 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included |
| 3 | Problem | `Problem` | [`search.py`][search] | Done | Included |
| 3 | Node | `Node` | [`search.py`][search] | Done | Included |
Expand Down Expand Up @@ -186,4 +186,4 @@ Many thanks for contributions over the years. I got bug reports, corrected code,
[rl]:../master/rl.py
[search]:../master/search.py
[utils]:../master/utils.py
[text]:../master/text.py
[text]:../master/text.py
39 changes: 37 additions & 2 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from agents import Direction
from agents import Agent
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \
SimpleReflexAgentProgram, rule_match


random.seed("aima-python")
Expand Down Expand Up @@ -130,7 +131,41 @@ def test_ReflexVacuumAgent() :
environment.run()
# check final status of the environment
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}


def test_SimpleReflexAgentProgram():
class Rule:

def __init__(self, state, action):
self.__state = state
self.action = action

def matches(self, state):
return self.__state == state

loc_A = (0, 0)
loc_B = (1, 0)

# create rules for a two state Vacuum Environment
rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"),
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]

def interpret_input(state):
return state

# create a program and then an object of the SimpleReflexAgentProgram
program = SimpleReflexAgentProgram(rules, interpret_input)
agent = Agent(program)
# create an object of TrivialVacuumEnvironment
environment = TrivialVacuumEnvironment()
# add agent to the environment
environment.add_thing(agent)
# run the environment
environment.run()
# check final status of the environment
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}




def test_ModelBasedVacuumAgent() :
# create an object of the ModelBasedVacuumAgent
Expand Down