Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector2: Add __radd__ #151

Merged
merged 3 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ppb_vector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def __add__(self, other: VectorLike) -> 'Vector':

return Vector(self.x + other_x, self.y + other_y)

def __radd__(self, other: VectorLike) -> 'Vector':
return self + other

def __sub__(self, other: VectorLike) -> 'Vector':
"""Subtract one vector from another.

Expand Down
8 changes: 8 additions & 0 deletions tests/test_addition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest # type: ignore
from hypothesis import given

from ppb_vector import Vector
from utils import vector_likes, vectors


def test_addition_vectors():
Expand Down Expand Up @@ -47,3 +49,9 @@ def test_addition_vector_dict():
@pytest.mark.parametrize("test_input, expected", data)
def test_multiples_values(test_input, expected):
assert (test_input[0] + test_input[1]) == expected


@given(x=vectors(), y=vectors())
def test_addition_reverse(x: Vector, y: Vector):
for y_like in vector_likes(y):
assert y_like + x == x + y