Skip to content

Commit

Permalink
tests/camera: Convert test_camera_viewport to Hypothesis
Browse files Browse the repository at this point in the history
  • Loading branch information
nbraud committed Apr 1, 2019
1 parent a90d8af commit fefa5a3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from hypothesis import given

from ppb import BaseSprite
from ppb import Vector
from ppb.camera import Camera
from ppb.testutils import integer_vectors


ONE_K = 1024
ONE_M = ONE_K * ONE_K


def test_camera_viewport():
cam = Camera(viewport=(0, 0, 800, 600))
assert cam.point_in_viewport(Vector(400, 400))
assert not cam.point_in_viewport(Vector(900, 600))
assert cam.viewport_offset == Vector(400, 300)
@given(diagonal=integer_vectors(min_value=2, max_value=ONE_M))
def test_camera_viewport(diagonal: Vector):
x, y = diagonal
cam = Camera(viewport=(0, 0, x, y))
assert cam.point_in_viewport(0.5 * diagonal)
assert not cam.point_in_viewport(diagonal + (100, 100))
assert cam.viewport_offset == 0.5 * diagonal


def test_camera_point_in_viewport_not_at_origin():
Expand Down

0 comments on commit fefa5a3

Please sign in to comment.