Skip to content
Merged
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
37 changes: 36 additions & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import random
from agents import Direction
from agents import Agent
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
RandomVacuumAgent


random.seed("aima-python")


def test_move_forward():
Expand Down Expand Up @@ -50,6 +55,19 @@ def test_add():
assert l2.direction == Direction.D


def test_RandomVacuumAgent() :
# create an object of the RandomVacuumAgent
agent = RandomVacuumAgent()
# 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_ReflexVacuumAgent() :
# create an object of the ReflexVacuumAgent
agent = ReflexVacuumAgent()
Expand All @@ -76,6 +94,23 @@ def test_ModelBasedVacuumAgent() :
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}


def test_compare_agents() :
environment = TrivialVacuumEnvironment
agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]

result = compare_agents(environment, agents)
performance_ModelBasedVacummAgent = result[0][1]
performance_ReflexVacummAgent = result[1][1]

# The performance of ModelBasedVacuumAgent will be at least as good as that of
# ReflexVacuumAgent, since ModelBasedVacuumAgent can identify when it has
# reached the terminal state (both locations being clean) and will perform
# NoOp leading to 0 performance change, whereas ReflexVacuumAgent cannot
# identify the terminal state and thus will keep moving, leading to worse
# performance compared to ModelBasedVacuumAgent.
assert performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent


def test_Agent():
def constant_prog(percept):
return percept
Expand Down