Skip to content

Commit 7e763e6

Browse files
ayushjain19norvig
authored andcommitted
Added TableDrivenAgentProgram tests (aimacode#777)
* Add tests for TableDrivenAgentProgram * Add tests for TableDrivenAgentProgram * Check environment status at every step * Check environment status at every step of TableDrivenAgentProgram
1 parent cc2d405 commit 7e763e6

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

tests/test_agents.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ def test_RandomVacuumAgent() :
8383
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
8484

8585

86-
def test_TableDrivenAgent() :
87-
#create a table that would consist of all the possible states of the agent
86+
def test_TableDrivenAgent():
8887
loc_A, loc_B = (0, 0), (1, 0)
89-
88+
# table defining all the possible states of the agent
9089
table = {((loc_A, 'Clean'),): 'Right',
9190
((loc_A, 'Dirty'),): 'Suck',
9291
((loc_B, 'Clean'),): 'Left',
@@ -98,17 +97,26 @@ def test_TableDrivenAgent() :
9897
((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
9998
((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck'
10099
}
100+
101101
# create an program and then an object of the TableDrivenAgent
102102
program = TableDrivenAgentProgram(table)
103103
agent = Agent(program)
104-
# create an object of the TrivialVacuumEnvironment
104+
# create an object of TrivialVacuumEnvironment
105105
environment = TrivialVacuumEnvironment()
106+
# initializing some environment status
107+
environment.status = {loc_A:'Dirty', loc_B:'Dirty'}
106108
# add agent to the environment
107109
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'}
110+
111+
# run the environment by single step everytime to check how environment evolves using TableDrivenAgentProgram
112+
environment.run(steps = 1)
113+
assert environment.status == {(1,0): 'Clean', (0,0): 'Dirty'}
114+
115+
environment.run(steps = 1)
116+
assert environment.status == {(1,0): 'Clean', (0,0): 'Dirty'}
117+
118+
environment.run(steps = 1)
119+
assert environment.status == {(1,0): 'Clean', (0,0): 'Clean'}
112120

113121

114122
def test_ReflexVacuumAgent() :

0 commit comments

Comments
 (0)