Skip to content
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

Add test for table_driven_agent_program and Random_agent_program #770

Merged
merged 8 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included |
| 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included |
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included |
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | 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.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included |
Expand Down Expand Up @@ -160,4 +160,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
45 changes: 44 additions & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from agents import Direction
from agents import Agent
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
RandomVacuumAgent, TableDrivenVacuumAgent
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram


random.seed("aima-python")
Expand Down Expand Up @@ -54,6 +54,21 @@ def test_add():
assert l1.direction == Direction.U
assert l2.direction == Direction.D

def test_RandomAgentProgram() :
#create a list of all the actions a vacuum cleaner can perform
list = ['Right', 'Left', 'Suck', 'NoOp']
# create a program and then an object of the RandomAgentProgram
program = RandomAgentProgram(list)

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_RandomVacuumAgent() :
# create an object of the RandomVacuumAgent
Expand All @@ -68,6 +83,34 @@ def test_RandomVacuumAgent() :
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}


def test_TableDrivenAgent() :
#create a table that would consist of all the possible states of the agent
loc_A, loc_B = (0, 0), (1, 0)

table = {((loc_A, 'Clean'),): 'Right',
((loc_A, 'Dirty'),): 'Suck',
((loc_B, 'Clean'),): 'Left',
((loc_B, 'Dirty'),): 'Suck',
((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right',
((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck',
((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left',
((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck'
}
# create an program and then an object of the TableDrivenAgent
program = TableDrivenAgentProgram(table)
agent = Agent(program)
# create an object of the 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_ReflexVacuumAgent() :
# create an object of the ReflexVacuumAgent
agent = ReflexVacuumAgent()
Expand Down