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

Skip to content

Commit c7fff61

Browse files
nouman-10norvig
authored andcommitted
Add test for table_driven_agent_program and Random_agent_program (aimacode#770)
* Add test for table driven agent * Some style fixes * Added done to tabledrivenagent test in readme * Added randomAgentProgram test to test_agents.py * Added Import randomAgentProgram * Style fixes * Added the done tag tp tabledrivenagent test
1 parent 84586ce commit c7fff61

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
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] | Done | 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 |
@@ -160,4 +160,4 @@ Many thanks for contributions over the years. I got bug reports, corrected code,
160160
[rl]:../master/rl.py
161161
[search]:../master/search.py
162162
[utils]:../master/utils.py
163-
[text]:../master/text.py
163+
[text]:../master/text.py

tests/test_agents.py

Lines changed: 44 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, TableDrivenVacuumAgent
5+
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram
66

77

88
random.seed("aima-python")
@@ -54,6 +54,21 @@ def test_add():
5454
assert l1.direction == Direction.U
5555
assert l2.direction == Direction.D
5656

57+
def test_RandomAgentProgram() :
58+
#create a list of all the actions a vacuum cleaner can perform
59+
list = ['Right', 'Left', 'Suck', 'NoOp']
60+
# create a program and then an object of the RandomAgentProgram
61+
program = RandomAgentProgram(list)
62+
63+
agent = Agent(program)
64+
# create an object of TrivialVacuumEnvironment
65+
environment = TrivialVacuumEnvironment()
66+
# add agent to the environment
67+
environment.add_thing(agent)
68+
# run the environment
69+
environment.run()
70+
# check final status of the environment
71+
assert environment.status == {(1, 0): 'Clean' , (0, 0): 'Clean'}
5772

5873
def test_RandomVacuumAgent() :
5974
# create an object of the RandomVacuumAgent
@@ -68,6 +83,34 @@ def test_RandomVacuumAgent() :
6883
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
6984

7085

86+
def test_TableDrivenAgent() :
87+
#create a table that would consist of all the possible states of the agent
88+
loc_A, loc_B = (0, 0), (1, 0)
89+
90+
table = {((loc_A, 'Clean'),): 'Right',
91+
((loc_A, 'Dirty'),): 'Suck',
92+
((loc_B, 'Clean'),): 'Left',
93+
((loc_B, 'Dirty'),): 'Suck',
94+
((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right',
95+
((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
96+
((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck',
97+
((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left',
98+
((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
99+
((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck'
100+
}
101+
# create an program and then an object of the TableDrivenAgent
102+
program = TableDrivenAgentProgram(table)
103+
agent = Agent(program)
104+
# create an object of the TrivialVacuumEnvironment
105+
environment = TrivialVacuumEnvironment()
106+
# add agent to the environment
107+
environment.add_thing(agent)
108+
# run the environment
109+
environment.run()
110+
# check final status of the environment
111+
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
112+
113+
71114
def test_ReflexVacuumAgent() :
72115
# create an object of the ReflexVacuumAgent
73116
agent = ReflexVacuumAgent()

0 commit comments

Comments
 (0)