diff --git a/tests/test_memory.py b/tests/test_memory.py index 571ca98e..d95e9afa 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -20,8 +20,7 @@ def __init__(self, x, y): @pytest.mark.skipif(sys.implementation.name != 'cpython', - reason="PyPy optimises __slots__ automatically.", -) + reason="PyPy optimises __slots__ automatically.") @given(x=floats(), y=floats()) def test_object_size(x, y): """Check that Vector2 is 2 times smaller than a naïve version.""" diff --git a/tests/test_vector2_rotate.py b/tests/test_vector2_rotate.py index c920ef82..a1d5fb49 100644 --- a/tests/test_vector2_rotate.py +++ b/tests/test_vector2_rotate.py @@ -16,43 +16,43 @@ (Vector2(1, 1), 180, Vector2(-1, -1)), ] + @pytest.mark.parametrize("input, angle, expected", data_exact, - ids=[str(angle) for _, angle, _ in data_exact], -) + ids=[str(angle) for _, angle, _ in data_exact]) def test_exact_rotations(input, angle, expected): assert input.rotate(angle) == expected assert input.angle(expected) == angle # angle (in degrees) -> (sin, cos) -## values from 0 to 45° -## lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference +# values from 0 to 45° +# lifted from https://en.wikibooks.org/wiki/Trigonometry/Selected_Angles_Reference remarkable_angles = { - 15: ((sqrt(6) - sqrt(2))/4, (sqrt(6) + sqrt(2))/4), - 22.5: (sqrt(2 - sqrt(2))/2, sqrt(2 + sqrt(2))/2), - 30: (0.5, sqrt(3)/2), - 45: (sqrt(2)/2, sqrt(2)/2), + 15: ((sqrt(6) - sqrt(2)) / 4, (sqrt(6) + sqrt(2)) / 4), + 22.5: (sqrt(2 - sqrt(2)) / 2, sqrt(2 + sqrt(2)) / 2), + 30: (0.5, sqrt(3) / 2), + 45: (sqrt(2) / 2, sqrt(2) / 2), } -## extend up to 90° +# extend up to 90° remarkable_angles.update({ 90 - angle: (cos_t, sin_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend up to 180° +# extend up to 180° remarkable_angles.update({ angle + 90: (cos_t, -sin_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend up to 360° +# extend up to 360° remarkable_angles.update({ angle + 180: (-sin_t, -cos_t) for angle, (sin_t, cos_t) in remarkable_angles.items() }) -## extend to negative angles +# extend to negative angles remarkable_angles.update({ -angle: (-sin_t, cos_t) for angle, (sin_t, cos_t) in remarkable_angles.items() @@ -60,8 +60,7 @@ def test_exact_rotations(input, angle, expected): @pytest.mark.parametrize("angle, trig", remarkable_angles.items(), - ids=[str(x) for x in remarkable_angles] -) + ids=[str(x) for x in remarkable_angles]) def test_remarkable_angles(angle, trig): _angle = math.radians(angle) sin_t, cos_t = trig @@ -79,11 +78,14 @@ def test_remarkable_angles(angle, trig): for (angle, (sin_t, cos_t)) in remarkable_angles.items() ] +data_close_ids = [ + f"(1,0).rotate({x})" for x in remarkable_angles +] + [ + f"(1,1).rotate({x})" for x in remarkable_angles +] + -@pytest.mark.parametrize("input, angle, expected", data_close, - ids=[f"(1,0).rotate({x})" for x in remarkable_angles] + - [f"(1,1).rotate({x})" for x in remarkable_angles], -) +@pytest.mark.parametrize("input, angle, expected", data_close, ids=data_close_ids) def test_close_rotations(input, angle, expected): assert input.rotate(angle).isclose(expected) assert angle_isclose(input.angle(expected), angle) @@ -111,7 +113,7 @@ def test_trig_stability(angle): def test_trig_invariance(angle: float, n: int): """Test that cos(θ), sin(θ) ≃ cos(θ + n*360°), sin(θ + n*360°)""" r_cos, r_sin = Vector2._trig(angle) - n_cos, n_sin = Vector2._trig(angle + 360*n) + n_cos, n_sin = Vector2._trig(angle + 360 * n) note(f"δcos: {r_cos - n_cos}") assert isclose(r_cos, n_cos, rel_to=[n / 1e9]) diff --git a/tests/test_vector2_scalar_multiplication.py b/tests/test_vector2_scalar_multiplication.py index 18d78bbb..e9bff73f 100644 --- a/tests/test_vector2_scalar_multiplication.py +++ b/tests/test_vector2_scalar_multiplication.py @@ -39,6 +39,7 @@ def test_scalar_division(x: Vector2, scalar: float): assume(abs(scalar) > 1e-100) assert (x / scalar).isclose((1 / scalar) * x) + @given(x=vectors(), scalar=floats()) def test_scalar_inverse(x: Vector2, scalar: float): """Test that (x / λ) = (1 / λ) * x"""