Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit c982df0

Browse files
committed
Fixed possible conversion but with Coord and Direction.
1 parent 4b03afa commit c982df0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/animate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Coord(NamedTuple):
4242
def __apply(self, op: Callable, other: Coord.Operand) -> Coord:
4343
if not isinstance(other, self.__class__):
4444
other = self.__class__(other, other)
45+
if isinstance(other, Direction):
46+
other = other.value
4547

4648
x = op(self.x, other.x)
4749
y = op(self.y, other.y)

src/test/test_coord.py renamed to src/test/test_animate.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..animate import Coord
1+
from ..animate import Coord, vector, Motion, Direction
22

33
coord1 = Coord(1, 1)
44
coord2 = Coord(1, 1)
@@ -37,3 +37,10 @@ def test_truediv():
3737
def test_floordiv():
3838
assert coord1 // coord2 == Coord(1, 1)
3939
assert coord1 // 1 == Coord(1, 1)
40+
41+
42+
def test_direction():
43+
assert Direction.UP.value == Direction.UP + Coord(0, 0)
44+
assert Direction.LEFT.value == Direction.LEFT + Coord(0, 0)
45+
assert Direction.RIGHT.value == Direction.RIGHT + Coord(0, 0)
46+
assert Direction.DOWN.value == Direction.DOWN + Coord(0, 0)

0 commit comments

Comments
 (0)