From df5cdc8b182a426a2f572ba6e53a17d7355dca49 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Sun, 25 Feb 2018 22:48:43 +0500 Subject: [PATCH 1/7] Add test for table driven agent --- tests/test_agents.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index eedaf0d76..0f8c41814 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -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 random.seed("aima-python") @@ -67,6 +67,34 @@ def test_RandomVacuumAgent() : # check final status of the environment 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 = (0,0) + loc_B = (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 From d79819ba0f7c724da455fa4b42cb7598146ae429 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 09:39:48 +0500 Subject: [PATCH 2/7] Some style fixes --- tests/test_agents.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 0f8c41814..2b1e84e41 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -69,8 +69,7 @@ def test_RandomVacuumAgent() : def test_TableDrivenAgent() : #create a table that would consist of all the possible states of the agent - loc_A = (0,0) - loc_B = (1,0) + loc_A, loc_B = (0, 0), (1, 0) table = {((loc_A, 'Clean'),): 'Right', ((loc_A, 'Dirty'),): 'Suck', @@ -93,7 +92,7 @@ def test_TableDrivenAgent() : # run the environment environment.run() # check final status of the environment - assert environment.status == {(1, 0):'Clean', (0, 0):'Clean'} + assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'} def test_ReflexVacuumAgent() : From a05bbfabfa40851c7cbd4b45a0a9f9f1cea18e66 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 09:41:37 +0500 Subject: [PATCH 3/7] Added done to tabledrivenagent test in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 847d43657..ca05da92f 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | Included | | 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.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.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included | From 89eb1c8eec4abb08c75091f460ba1892258816cc Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 09:54:31 +0500 Subject: [PATCH 4/7] Added randomAgentProgram test to test_agents.py --- tests/test_agents.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_agents.py b/tests/test_agents.py index 2b1e84e41..27c5283d5 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -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 @@ -67,6 +82,7 @@ def test_RandomVacuumAgent() : # check final status of the environment 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) From 574b520bcd0585f01e2497cbd6dbd19d544ceb95 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 10:19:21 +0500 Subject: [PATCH 5/7] Added Import randomAgentProgram --- tests/test_agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 27c5283d5..9340f4a95 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -2,7 +2,7 @@ from agents import Direction from agents import Agent from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\ - RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram + RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram random.seed("aima-python") From 935e1285be32025d033caeb9d0b7ac8d76e21ccf Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 22:52:55 +0500 Subject: [PATCH 6/7] Style fixes --- tests/test_agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 9340f4a95..73b149f99 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -68,7 +68,7 @@ def test_RandomAgentProgram() : # run the environment environment.run() # check final status of the environment - assert environment.status == {(1,0): 'Clean' , (0,0): 'Clean'} + assert environment.status == {(1, 0): 'Clean' , (0, 0): 'Clean'} def test_RandomVacuumAgent() : # create an object of the RandomVacuumAgent From 8ac23082773be46a940a0023b107ced892edcdc2 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Mon, 26 Feb 2018 23:01:14 +0500 Subject: [PATCH 7/7] Added the done tag tp tabledrivenagent test --- README.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5781e7a1c..21a63448f 100644 --- a/README.md +++ b/README.md @@ -34,19 +34,8 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included | | 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included | -<<<<<<< HEAD -| 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.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included | -| 3 | Problem | `Problem` | [`search.py`][search] | Done | | -| 3 | Node | `Node` | [`search.py`][search] | Done | | -| 3 | Queue | `Queue` | [`utils.py`][utils] | Done | No Need | -| 3.1 | Simple-Problem-Solving-Agent | `SimpleProblemSolvingAgent` | [`search.py`][search] | | 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 | @@ -54,7 +43,6 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 3 | Node | `Node` | [`search.py`][search] | Done | Included | | 3 | Queue | `Queue` | [`utils.py`][utils] | Done | No Need | | 3.1 | Simple-Problem-Solving-Agent | `SimpleProblemSolvingAgent` | [`search.py`][search] | | Included | ->>>>>>> upstream/master | 3.2 | Romania | `romania` | [`search.py`][search] | Done | Included | | 3.7 | Tree-Search | `tree_search` | [`search.py`][search] | Done | | | 3.7 | Graph-Search | `graph_search` | [`search.py`][search] | Done | | @@ -172,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 \ No newline at end of file