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 ppb#75
  • Loading branch information
nbraud committed Dec 16, 2018
1 parent 9feaf1f commit e57c217
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 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())
24 changes: 12 additions & 12 deletions tests/test_vector2_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,27 @@ def test_rotation_stability2(initial, angles):


@given(
a=vectors(max_magnitude=1e150), b=vectors(),
x=vectors(max_magnitude=1e150), y=vectors(),
l=st.floats(min_value=-1e150, max_value=1e150),
angle=st.floats(min_value=-360, max_value=360),
)
# 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: 7 additions & 7 deletions tests/test_vector2_scalar_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def test_scalar_multiplication(x, y, expected):


@given(
x=floats(min_value=-1e75, max_value=1e75),
y=floats(min_value=-1e75, max_value=1e75),
v=vectors(max_magnitude=1e150)
l=floats(min_value=-1e75, max_value=1e75),
m=floats(min_value=-1e75, max_value=1e75),
x=vectors(max_magnitude=1e150)
)
def test_scalar_associative(x: float, y: float, v: Vector2):
"""(x * y) * v == x * (y * v)"""
left = (x * y) * v
right = x * (y * v)
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(
Expand Down

0 comments on commit e57c217

Please sign in to comment.