From ae0d9d16aa94b9252612af25c674dab88f3ee4ec Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 8 Mar 2017 02:57:13 +0530 Subject: [PATCH 1/3] adding tests for agent directions --- tests/test_agents.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_agents.py diff --git a/tests/test_agents.py b/tests/test_agents.py new file mode 100644 index 000000000..73bac37ec --- /dev/null +++ b/tests/test_agents.py @@ -0,0 +1,40 @@ +from agents import Direction + +def test_move_forward(): + d = Direction("up") + l1 = d.move_forward((0,0)) + assert l1 == (0,-1) + d = Direction(Direction.R) + l1 = d.move_forward((0,0)) + assert l1 == (1,0) + d = Direction(Direction.D) + l1 = d.move_forward((0,0)) + assert l1 == (0,1) + d = Direction("left") + l1 = d.move_forward((0,0)) + assert l1 == (-1,0) + l2 = d.move_forward((1,0)) + assert l2 == (0,0) + +def test_add(): + d = Direction(Direction.U) + l1 = d + "right" + l2 = d + "left" + assert l1.direction == Direction.R + assert l2.direction == Direction.L + d = Direction("right") + l1 = d.__add__(Direction.L) + l2 = d.__add__(Direction.R) + assert l1.direction == "up" + assert l2.direction == "down" + d = Direction("down") + l1 = d.__add__("right") + l2 = d.__add__("left") + assert l1.direction == Direction.L + assert l2.direction == Direction.R + d = Direction(Direction.L) + l1 = d + Direction.R + l2 = d + Direction.L + assert l1.direction == Direction.U + #assert l2.direction == Direction.D currently gives an error - need to fix bug in agents.py + From f8b257c23730f2fe158a8be8d4e214720ce87510 Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 8 Mar 2017 03:01:18 +0530 Subject: [PATCH 2/3] added test that fails due to bug in agents.py --- 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 73bac37ec..89ee3fcf3 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -36,5 +36,5 @@ def test_add(): l1 = d + Direction.R l2 = d + Direction.L assert l1.direction == Direction.U - #assert l2.direction == Direction.D currently gives an error - need to fix bug in agents.py + assert l2.direction == Direction.D #fixed From adfae75f91e70f1c9159b6064a9ca5902ad9455c Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 8 Mar 2017 03:01:58 +0530 Subject: [PATCH 3/3] fixed direction error: L + L = D --- agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents.py b/agents.py index a5bf376ca..adb3f9bbc 100644 --- a/agents.py +++ b/agents.py @@ -345,7 +345,7 @@ def __add__(self, heading): elif self.direction == self.L: return{ self.R: Direction(self.U), - self.L: Direction(self.L), + self.L: Direction(self.D), }.get(heading, None) elif self.direction == self.U: return{