From fefa5a383f43260dfc58fbf700f462e9825c2e87 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Sun, 31 Mar 2019 20:41:53 +0200 Subject: [PATCH] tests/camera: Convert test_camera_viewport to Hypothesis --- tests/test_camera.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_camera.py b/tests/test_camera.py index 87959a96..b5906a33 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -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():