Skip to content

Commit

Permalink
tests: Uniformize single-letter variable names
Browse files Browse the repository at this point in the history
- x, y, ... are vectors
- l, m, ... are scalars

Closes #75
  • Loading branch information
nbraud committed Jan 18, 2019
1 parent 4026ad3 commit 7990058
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
12 changes: 6 additions & 6 deletions tests/test_vector2_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import ppb_vector


@given(v=vectors())
def test_normalize_length(v):
"""v.normalize().length == 1 and v == v.length * v.normalize()"""
assume(v != (0, 0))
assert isclose(v.normalize().length, 1)
assert v.isclose(v.length * v.normalize())
@given(x=vectors())
def test_normalize_length(x):
"""x.normalize().length == 1 and x == x.length * x.normalize()"""
assume(x != (0, 0))
assert isclose(x.normalize().length, 1)
assert x.isclose(x.length * x.normalize())
28 changes: 16 additions & 12 deletions tests/test_vector2_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,28 @@ def test_rotation_stability2(initial, angles):
assert math.isclose(fellswoop.length, initial.length, rel_tol=1e-15)


@given(a=vectors(), b=vectors(), l=floats(), angle=angles())
@given(
x=vectors(), y=vectors(),
l=floats(),
angle=angles(),
)
# In this example:
# * a * l == -b
# * x * l == -y
# * Rotation must not be an multiple of 90deg
# * Must be sufficiently large
@example(
a=Vector2(1e10, 1e10),
b=Vector2(1e19, 1e19),
x=Vector2(1e10, 1e10),
y=Vector2(1e19, 1e19),
l=-1e9,
angle=45,
)
def test_rotation_linearity(a, b, l, angle):
"""(l*a + b).rotate is equivalent to l*a.rotate + b.rotate"""
inner = (l * a + b).rotate(angle)
outer = l * a.rotate(angle) + b.rotate(angle)
note(f"l * a + b: {l * a + b}")
note(f"l * a.rotate(): {l * a.rotate(angle)}")
note(f"b.rotate(): {b.rotate(angle)}")
def test_rotation_linearity(x, y, l, angle):
"""(l*x + y).rotate is equivalent to l*x.rotate + y.rotate"""
inner = (l * x + y).rotate(angle)
outer = l * x.rotate(angle) + y.rotate(angle)
note(f"l * x + y: {l * x + y}")
note(f"l * x.rotate(): {l * x.rotate(angle)}")
note(f"y.rotate(): {y.rotate(angle)}")
note(f"Inner: {inner}")
note(f"Outer: {outer}")
assert inner.isclose(outer, rel_to=[a, l * a, b])
assert inner.isclose(outer, rel_to=[x, l * x, y])
14 changes: 9 additions & 5 deletions tests/test_vector2_scalar_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def test_scalar_coordinates(scalar: float, vector: Vector2):
assert scalar * vector.y == (scalar * vector).y


@given(x=floats(), y=floats(), v=vectors())
def test_scalar_associative(x: float, y: float, v: Vector2):
"""(x * y) * v == x * (y * v)"""
left = (x * y) * v
right = x * (y * v)
@given(
l=floats(),
m=floats(),
x=vectors()
)
def test_scalar_associative(l: float, m: float, x: Vector2):
"""(l * m) * x == l * (m * x)"""
left = (l * m) * x
right = l * (m * x)
assert left.isclose(right)

@given(l=floats(), x=vectors(), y=vectors())
Expand Down

0 comments on commit 7990058

Please sign in to comment.