From a3b16970aea152172721f579ba4045409bbddc70 Mon Sep 17 00:00:00 2001 From: hoffmeisterda104361 Date: Mon, 9 Nov 2026 10:37:48 +0100 Subject: [PATCH] added tests --- test/__init__.py | 1 + test/conftest.py | 2 ++ test/test_cube_game.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/__init__.py create mode 100644 test/conftest.py create mode 100644 test/test_cube_game.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..7b9b859 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,2 @@ +# pytest configuration +# Use default settings. diff --git a/test/test_cube_game.py b/test/test_cube_game.py new file mode 100644 index 0000000..c92988f --- /dev/null +++ b/test/test_cube_game.py @@ -0,0 +1,29 @@ +import pygame + +from game.cube_game import CubeGame +from game.compute import rot_3d + +def test_rot_3d_z_90(): + # Rotating point [1, 0, 0] around z by 90 degrees should give [0, 1, 0] + points = [[1.0, 0.0, 0.0]] + rotated = rot_3d(points, 90.0, "z") + assert round(rotated[0][0], 5) == 0.0 + assert round(rotated[0][1], 5) == 1.0 + assert round(rotated[0][2], 5) == 0.0 + +def test_no_key_pressed(): + game = CubeGame() + initial = game.rotation.copy() + game.update_game() + assert game.rotation == initial + +def test_key_press_increments_rotation(): + game = CubeGame() + event = pygame.event.Event(pygame.KEYDOWN, key=pygame.K_UP) + game.handle_event(event) + game.update_game() + assert game.rotation["x"] == 1.0 + event_up = pygame.event.Event(pygame.KEYUP, key=pygame.K_UP) + game.handle_event(event_up) + game.update_game() + assert game.rotation["x"] == 1.0