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

tests/utils: Freeze all the operators sets #156

Merged
merged 2 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
6 changes: 3 additions & 3 deletions tests/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
y = Vector(0, 1)
scalar = 123

for f in BINARY_OPS + BINARY_SCALAR_OPS + BOOL_OPS: # type: ignore
for f in BINARY_OPS | BINARY_SCALAR_OPS | BOOL_OPS: # type: ignore
r.bench_func(f.__name__, f, x, y)

for f in UNARY_OPS + UNARY_SCALAR_OPS: # type: ignore
for f in UNARY_OPS | UNARY_SCALAR_OPS: # type: ignore
r.bench_func(f.__name__, f, x)

for f in SCALAR_OPS: # type: ignore
r.bench_func(f.__name__, f, x, scalar)
r.bench_func(f.__name__, f, x, scalar) # type: ignore
2 changes: 1 addition & 1 deletion tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from utils import *


@pytest.mark.parametrize("op", BINARY_OPS + BINARY_SCALAR_OPS + BOOL_OPS) # type: ignore
@pytest.mark.parametrize("op", BINARY_OPS | BINARY_SCALAR_OPS | BOOL_OPS) # type: ignore
@given(x=vectors(), y=units())
def test_binop_vectorlike(op, x: Vector, y: Vector):
"""Test that `op` accepts a vector-like second parameter."""
Expand Down
16 changes: 9 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,28 @@ def isclose(


# List of operations that (Vector, Vector) -> Vector
BINARY_OPS = [Vector.__add__, Vector.__sub__, Vector.reflect]
BINARY_OPS = frozenset({Vector.__add__, Vector.__sub__, Vector.reflect})

# List of (Vector, Vector) -> scalar operations
BINARY_SCALAR_OPS = [Vector.angle, Vector.dot]
BINARY_SCALAR_OPS = frozenset({Vector.angle, Vector.dot})

# List of (Vector, Vector) -> bool operations
BOOL_OPS = [Vector.__eq__, Vector.isclose]
BOOL_OPS = frozenset({Vector.__eq__, Vector.isclose})

# List of operations that (Vector, Real) -> Vector
SCALAR_OPS = [Vector.rotate, Vector.scale_by, Vector.scale_to, Vector.truncate]
SCALAR_OPS = frozenset({
Vector.rotate, Vector.scale_by, Vector.scale_to, Vector.truncate,
})

# List of operations that (Vector) -> Vector
UNARY_OPS = [Vector.__neg__, Vector, Vector.normalize]
UNARY_OPS = frozenset({Vector.__neg__, Vector, Vector.normalize})

# List of (Vector) -> scalar operations
UNARY_SCALAR_OPS = [
UNARY_SCALAR_OPS = frozenset({
Vector.length.fget, # type: ignore
# mypy fails to typecheck properties' attributes:
# https://github.com/python/mypy/issues/220
]
})


# Sequence of vector-likes equivalent to the input vector (def. to the x vector)
Expand Down