diff --git a/tests/collision.py b/tests/collision.py new file mode 100644 index 0000000..483039f --- /dev/null +++ b/tests/collision.py @@ -0,0 +1,41 @@ +import sys +sys.path.insert(0, '.') +import play +import pytest + +radius = 20 +x_speed = 6 # even number for testing +num_collisions = 0 + +ball = play.new_circle('black', + x=0, + y=0, + radius=radius) + +ball.start_physics(x_speed=x_speed, + obeys_gravity=False) + + +box = play.new_box(color='black', + x=300, + y=0, + width=30, + height=300, + border_color="black", + border_width=10) + +@play.repeat_forever +def check(): + if ball.x < 0: + if num_collisions != 1: + pytest.fail(f'num_collisions ({num_collisions}) should be one') + sys.exit() + +@ball.when_touching(box) +def collision(): + global num_collisions + num_collisions += 1 + ball.x = 0 + ball.physics.x_speed = -10 + +play.start_program() \ No newline at end of file diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100644 index 0000000..b1cc7a8 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,4 @@ +cd .. +python tests/x_speed.py & +python tests/y_speed.py & +python tests/collision.py & \ No newline at end of file diff --git a/tests/x_speed.py b/tests/x_speed.py new file mode 100644 index 0000000..1c4d3c8 --- /dev/null +++ b/tests/x_speed.py @@ -0,0 +1,29 @@ +import sys +sys.path.insert(0, '.') +import play +import pytest + +radius = 20 +x_speed = 6 # even number for testing +num_frames = 0 + +ball = play.new_circle('black', + x=0, + y=0, + radius=radius) + +ball.start_physics(x_speed=x_speed, + obeys_gravity=False) + + +@play.repeat_forever +def always(): + global num_frames + if num_frames < ((play.globals.WIDTH/2) - radius): + if round(ball.x) != num_frames: + pytest.fail(f'expected ball.x ({ball.x}) to be num of frames ({num_frames})') + else: + sys.exit() + num_frames += 1 + +play.start_program() diff --git a/tests/y_speed.py b/tests/y_speed.py new file mode 100644 index 0000000..cd41391 --- /dev/null +++ b/tests/y_speed.py @@ -0,0 +1,29 @@ +import sys +sys.path.insert(0, '.') +import play +import pytest + +radius = 20 +y_speed = 6 # even number for testing +num_frames = 0 + +ball = play.new_circle('black', + x=0, + y=0, + radius=radius) + +ball.start_physics(y_speed=y_speed, + obeys_gravity=False) + + +@play.repeat_forever +def always(): + global num_frames + if num_frames < ((play.globals.HEIGHT/2) - radius): + if round(ball.y) != num_frames: + pytest.fail(f'expected ball.y ({ball.y}) to be num of frames ({num_frames})') + else: + sys.exit() + num_frames += 1 + +play.start_program()