From 2446f129a8776cdd73822373035dab1bee27d13a Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Thu, 1 Mar 2018 02:01:21 +0500 Subject: [PATCH 1/3] Added test for simpleProblemSolvingAgent --- tests/test_search.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/test_search.py b/tests/test_search.py index 04cb2db35..ab873d562 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -199,7 +199,44 @@ def GA_GraphColoringInts(edges, fitness): population = init_population(8, [0, 1], 4) return genetic_algorithm(population, fitness) - +def test_simpleProblemSolvingAgent(): + class vacuumAgent(SimpleProblemSolvingAgentProgram): + def update_state(self, state, percept): + state = percept + return state + def formulate_goal(self, state): + goal = [state7, state8] + return goal + def formulate_problem(self, state, goal): + problem = state + return problem + def search(self, problem): + if (problem == state1): + seq = ["Suck", "Right", "Suck"] + elif (problem == state2): + seq = ["Suck", "Left", "Suck"] + elif (problem == state3): + seq = ["Right", "Suck"] + elif (problem == state4): + seq = ["Suck"] + elif (problem == state5): + seq = ["Suck"] + elif (problem == state6): + seq = ["Left", "Suck"] + return seq + state1 = [(0, 0), [(0, 0), "Dirty"], [(1, 0), ["Dirty"]]] + state2 = [(1, 0), [(0, 0), "Dirty"], [(1, 0), ["Dirty"]]] + state3 = [(0, 0), [(0, 0), "Clean"], [(1, 0), ["Dirty"]]] + state4 = [(1, 0), [(0, 0), "Clean"], [(1, 0), ["Dirty"]]] + state5 = [(0, 0), [(0, 0), "Dirty"], [(1, 0), ["Clean"]]] + state6 = [(1, 0), [(0, 0), "Dirty"], [(1, 0), ["Clean"]]] + state7 = [(0, 0), [(0, 0), "Clean"], [(1, 0), ["Clean"]]] + state8 = [(1, 0), [(0, 0), "Clean"], [(1, 0), ["Clean"]]] + a = vacuumAgent(state1) + assert a.__call__(state6) == "Left" + assert a.__call__(state1) == "Suck" + assert a.__call__(state3) == "Right" + # TODO: for .ipynb: From 0460a4bdd62625bb584dab0f91e9d67d6938eab1 Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Thu, 1 Mar 2018 10:04:00 +0500 Subject: [PATCH 2/3] Some Style fixes --- tests/test_search.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/test_search.py b/tests/test_search.py index ab873d562..f424e299b 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -199,31 +199,36 @@ def GA_GraphColoringInts(edges, fitness): population = init_population(8, [0, 1], 4) return genetic_algorithm(population, fitness) + + def test_simpleProblemSolvingAgent(): class vacuumAgent(SimpleProblemSolvingAgentProgram): - def update_state(self, state, percept): - state = percept - return state + def update_state(self, percept): + return percept + def formulate_goal(self, state): goal = [state7, state8] return goal + def formulate_problem(self, state, goal): problem = state - return problem + return problem + def search(self, problem): - if (problem == state1): + if problem == state1: seq = ["Suck", "Right", "Suck"] - elif (problem == state2): + elif problem == state2: seq = ["Suck", "Left", "Suck"] - elif (problem == state3): + elif problem == state3: seq = ["Right", "Suck"] - elif (problem == state4): + elif problem == state4: seq = ["Suck"] - elif (problem == state5): + elif problem == state5: seq = ["Suck"] - elif (problem == state6): + elif problem == state6: seq = ["Left", "Suck"] return seq + state1 = [(0, 0), [(0, 0), "Dirty"], [(1, 0), ["Dirty"]]] state2 = [(1, 0), [(0, 0), "Dirty"], [(1, 0), ["Dirty"]]] state3 = [(0, 0), [(0, 0), "Clean"], [(1, 0), ["Dirty"]]] @@ -232,10 +237,12 @@ def search(self, problem): state6 = [(1, 0), [(0, 0), "Dirty"], [(1, 0), ["Clean"]]] state7 = [(0, 0), [(0, 0), "Clean"], [(1, 0), ["Clean"]]] state8 = [(1, 0), [(0, 0), "Clean"], [(1, 0), ["Clean"]]] + a = vacuumAgent(state1) - assert a.__call__(state6) == "Left" - assert a.__call__(state1) == "Suck" - assert a.__call__(state3) == "Right" + + assert a(state6) == "Left" + assert a(state1) == "Suck" + assert a(state3) == "Right" From 6502165a0c61261bd419912310d4a93e35016d4f Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Thu, 1 Mar 2018 10:07:47 +0500 Subject: [PATCH 3/3] Fixed update_state in test_search.py --- tests/test_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_search.py b/tests/test_search.py index f424e299b..23f8b0f43 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -203,7 +203,7 @@ def GA_GraphColoringInts(edges, fitness): def test_simpleProblemSolvingAgent(): class vacuumAgent(SimpleProblemSolvingAgentProgram): - def update_state(self, percept): + def update_state(self, state, percept): return percept def formulate_goal(self, state): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy