Skip to content

Commit

Permalink
Merge #152
Browse files Browse the repository at this point in the history
152: tests: Add tests for __rmul__ (scalar and dot products) r=astronouth7303 a=nbraud



Co-authored-by: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
  • Loading branch information
bors[bot] and nbraud committed May 23, 2019
2 parents cd4a5fe + 7e17aa1 commit cefdccf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hypothesis import assume, given, note

from ppb_vector import Vector
from utils import angles, floats, isclose, vectors
from utils import angles, floats, isclose, vector_likes, vectors


@given(vector=vectors())
Expand Down Expand Up @@ -75,3 +75,9 @@ def test_dot_from_angle(x: Vector, y: Vector):
note(f"algebraic: {x * y}")
note(f"geometric: {geometric}")
assert isclose(x * y, geometric, rel_to=(x, y), rel_exp=2)


@given(x=vectors(), y=vectors())
def test_dot_rmul(x: Vector, y: Vector):
for x_like in vector_likes(x):
assert x_like * y == x * y
5 changes: 5 additions & 0 deletions tests/test_scalar_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ def test_scalar_inverse(x: Vector, scalar: float):
"""Test that (λ * x / λ) ≃ x"""
assume(abs(scalar) > 1e-100)
assert x.isclose(scalar * x / scalar)


@given(x=vectors(), scalar=floats())
def test_scalar_rmul(x: Vector, scalar: float):
assert scalar * x == x.scale_by(scalar)

0 comments on commit cefdccf

Please sign in to comment.