FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Corrected Direction arithmetic in agents.py by kaivalyar · Pull Request #348 · aimacode/aima-python · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion agents.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
40 changes: 40 additions & 0 deletions tests/test_agents.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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 #fixed


Back | FazBrowse Home | New Git URL