From 7681b345b598a7920bda4a4c8edfdd1d40dfbc47 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Tue, 29 Jul 2025 21:21:25 +1000 Subject: [PATCH 01/10] Add camera tests --- .../src/test/unit_tests/unit_test_camera.cpp | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 coresdk/src/test/unit_tests/unit_test_camera.cpp diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp new file mode 100644 index 00000000..ede8f3df --- /dev/null +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -0,0 +1,163 @@ +/** + * Camera Tests + */ + +#include "catch.hpp" + +#include "camera.h" + +using namespace splashkit_lib; + +TEST_CASE("Camera position correct after setting position", "[camera][integration]") +{ + set_camera_position(point_at(42.0, 100.0)); + + point_2d result = camera_position(); + REQUIRE(result.x == Approx(42.0)); + REQUIRE(result.y == Approx(100.0)); +} + +TEST_CASE("Get screen center in world space", "[camera][graphics][window][integration]") +{ + open_window("", 100, 100); + point_2d result = screen_center(); + REQUIRE(result.x == Approx(50.0)); + REQUIRE(result.y == Approx(50.0)); + close_current_window(); +} + +TEST_CASE("Convert world space to screen space", "[camera][unit]") +{ + set_camera_position(point_at(150.0, 150.0)); + + SECTION("World x to screen space") + { + REQUIRE(to_screen_x(100.0) == Approx(50.0)); + } + SECTION("World y to screen space") + { + REQUIRE(to_screen_y(100.0) == Approx(50.0)); + } + SECTION("World point to screen space") + { + point_2d result = to_screen(point_at(100.0, 100.0)); + REQUIRE(result.x == Approx(50.0)); + REQUIRE(result.y == Approx(50.0)); + } + SECTION("World vector to screen space") + { + vector_2d result = vector_world_to_screen(); + REQUIRE(result.x == Approx(-50.0)); + REQUIRE(result.y == Approx(-50.0)); + } +} + +TEST_CASE("Convert rectangle to screen space", "[camera][rectangle_geometry][graphics][window][integration]") +{ + // TODO +} + +TEST_CASE("Return window as rectangle", "[camera][rectangle_geometry][graphics][window][integration]") +{ + SECTION("Rectangle from screen") + { + // TODO + + } + SECTION("Rectangle from window") + { + // TODO + + } +} + +TEST_CASE("Convert screen space to world space", "[camera][unit]") +{ + SECTION("Screen x to world space") + { + // TODO + } + SECTION("Screen y to world space") + { + // TODO + } + SECTION("Screen point to world space") + { + // TODO + } +} + +TEST_CASE("Check if rectangle is on screen", "[camera][rectangle_geometry][graphics][window][integration]") +{ + SECTION("Rectangle is on screen") + { + SECTION("Rectangle is on screen") + { + // TODO + + } + SECTION("Rectangle is in given window") + { + // TODO + + } + } + SECTION("Rectangle is off screen") + { + SECTION("Rectangle is off screen") + { + // TODO + + } + SECTION("Rectangle is out of given window") + { + // TODO + + } + } +} + +TEST_CASE("Check if point is on screen", "[camera][point_geometry][graphics][window][integration]") +{ + SECTION("Point is on screen") + { + SECTION("Point is on screen") + { + // TODO + + } + SECTION("Point is in given window") + { + // TODO + + } + } + SECTION("Point is off screen") + { + SECTION("Point is off screen") + { + // TODO + + } + SECTION("Point is out of given window") + { + // TODO + + } + } +} + +TEST_CASE("Can move camera to coordinates", "[camera][unit]") +{ + // TODO +} + +TEST_CASE("Can move camera by offset", "[camera][unit]") +{ + // TODO +} + +TEST_CASE("Can center camera on sprite", "[camera][sprite][integration]") +{ + // TODO +} \ No newline at end of file From 078a790e7b025f1e90d15b9b49db4bd908c992c9 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 30 Jul 2025 18:05:57 +1000 Subject: [PATCH 02/10] Add more tests --- .../src/test/unit_tests/unit_test_camera.cpp | 153 +++++++++++------- 1 file changed, 92 insertions(+), 61 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index ede8f3df..89bec449 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -7,22 +7,21 @@ #include "camera.h" using namespace splashkit_lib; +using Catch::Matchers::WithinRel; -TEST_CASE("Camera position correct after setting position", "[camera][integration]") +TEST_CASE("Camera position correct after moving", "[camera][unit]") { set_camera_position(point_at(42.0, 100.0)); - - point_2d result = camera_position(); - REQUIRE(result.x == Approx(42.0)); - REQUIRE(result.y == Approx(100.0)); + REQUIRE_THAT(camera_x(), WithinRel(42.0)); + REQUIRE_THAT(camera_y(), WithinRel(100.0)); } TEST_CASE("Get screen center in world space", "[camera][graphics][window][integration]") { - open_window("", 100, 100); - point_2d result = screen_center(); - REQUIRE(result.x == Approx(50.0)); - REQUIRE(result.y == Approx(50.0)); + open_window("Get screen center in world space", 100, 100); + point_2d center = screen_center(); + REQUIRE_THAT(center.x, WithinRel(50.0)); + REQUIRE_THAT(center.y, WithinRel(50.0)); close_current_window(); } @@ -32,132 +31,164 @@ TEST_CASE("Convert world space to screen space", "[camera][unit]") SECTION("World x to screen space") { - REQUIRE(to_screen_x(100.0) == Approx(50.0)); + REQUIRE_THAT(to_screen_x(160.0), WithinRel(10.0)); } SECTION("World y to screen space") { - REQUIRE(to_screen_y(100.0) == Approx(50.0)); + REQUIRE_THAT(to_screen_y(160.0), WithinRel(10.0)); } SECTION("World point to screen space") { - point_2d result = to_screen(point_at(100.0, 100.0)); - REQUIRE(result.x == Approx(50.0)); - REQUIRE(result.y == Approx(50.0)); + point_2d result = to_screen(point_at(160.0, 160.0)); + REQUIRE_THAT(result.x, WithinRel(10.0)); + REQUIRE_THAT(result.y, WithinRel(10.0)); } SECTION("World vector to screen space") { vector_2d result = vector_world_to_screen(); - REQUIRE(result.x == Approx(-50.0)); - REQUIRE(result.y == Approx(-50.0)); + REQUIRE_THAT(result.x, WithinRel(-150.0)); + REQUIRE_THAT(result.y, WithinRel(-150.0)); } } -TEST_CASE("Convert rectangle to screen space", "[camera][rectangle_geometry][graphics][window][integration]") -{ - // TODO -} +// Superfluous - tested with rect_on_screen integration +// TEST_CASE("Convert rectangle to screen space", "[camera][rectangle_geometry][graphics][window][integration]") +// { +// // TODO +// } -TEST_CASE("Return window as rectangle", "[camera][rectangle_geometry][graphics][window][integration]") -{ - SECTION("Rectangle from screen") - { - // TODO +// TEST_CASE("Return window as rectangle", "[camera][rectangle_geometry][graphics][window][integration]") +// { +// SECTION("Rectangle from screen") +// { +// // TODO - } - SECTION("Rectangle from window") - { - // TODO +// } +// SECTION("Rectangle from window") +// { +// // TODO - } -} +// } +// } TEST_CASE("Convert screen space to world space", "[camera][unit]") { + set_camera_position(point_at(150.0, 150.0)); + SECTION("Screen x to world space") { - // TODO + REQUIRE_THAT(to_world_x(100.0), WithinRel(250.0)); } SECTION("Screen y to world space") { - // TODO + REQUIRE_THAT(to_world_y(100.0), WithinRel(250.0)); } SECTION("Screen point to world space") { - // TODO + point_2d result = to_world(point_at(100.0, 100.0)); + REQUIRE_THAT(result.x, WithinRel(250.0)); + REQUIRE_THAT(result.y, WithinRel(250.0)); } } TEST_CASE("Check if rectangle is on screen", "[camera][rectangle_geometry][graphics][window][integration]") { - SECTION("Rectangle is on screen") + window wind = open_window("Check if rectangle is on screen", 100, 100); + + SECTION("50x50 rectangle at 0,0") { + rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); + SECTION("Rectangle is on screen") { - // TODO - + REQUIRE(rect_on_screen(rect)); } SECTION("Rectangle is in given window") { - // TODO - + REQUIRE(rect_in_window(wind, rect)); } } - SECTION("Rectangle is off screen") + SECTION("50x50 rectangle at 100.1,100.1") { + rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); + SECTION("Rectangle is off screen") { - // TODO - + REQUIRE_FALSE(rect_on_screen(rect)); } SECTION("Rectangle is out of given window") { - // TODO - + REQUIRE_FALSE(rect_in_window(wind, rect)); } } + close_window(wind); } TEST_CASE("Check if point is on screen", "[camera][point_geometry][graphics][window][integration]") { - SECTION("Point is on screen") + window wind = open_window("Check if point is on screen", 100, 100); + + SECTION("Point at 50,50") { + point_2d pt = point_at(50.0, 50.0); + SECTION("Point is on screen") { - // TODO - + REQUIRE(point_on_screen(pt)); } SECTION("Point is in given window") { - // TODO - + REQUIRE(point_in_window(wind, pt)); } } - SECTION("Point is off screen") + SECTION("Point at 100.1,100.1") { + point_2d pt = point_at(100.1, 100.1); + SECTION("Point is off screen") { - // TODO - + REQUIRE_FALSE(point_on_screen(pt)); } SECTION("Point is out of given window") { - // TODO - + REQUIRE_FALSE(point_in_window(wind, pt)); } } + close_window(wind); } -TEST_CASE("Can move camera to coordinates", "[camera][unit]") -{ - // TODO -} +// Redundant +// TEST_CASE("Can move camera to coordinates", "[camera][unit]") +// { +// // TODO +// } TEST_CASE("Can move camera by offset", "[camera][unit]") { - // TODO + move_camera_by(42.0, 100.0); + REQUIRE_THAT(camera_x(), WithinRel(42.0)); + REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE("Can center camera on sprite", "[camera][sprite][integration]") +TEST_CASE("Can center camera on sprite", "[camera][bitmap][sprite][integration]") { - // TODO + // Create 20x20 square sprite at 50,50 + bitmap square_bmp = create_bitmap("square", 20, 20); + sprite square_sprt = create_sprite(square_bmp); + move_sprite_to(square_sprt, 50.0, 50.0); + + SECTION("Camera moves to sprite with no offset") + { + vector_2d offset = vector_to(0.0, 0.0); + center_camera_on(square_sprt, offset); + REQUIRE_THAT(camera_x(), WithinRel(50.0)); + REQUIRE_THAT(camera_y(), WithinRel(50.0)); + } + SECTION("Camera moves to sprite with offset") + { + vector_2d offset = vector_to(0.5, 0.5); + center_camera_on(square_sprt, offset); + REQUIRE_THAT(camera_x(), WithinRel(50.5)); + REQUIRE_THAT(camera_y(), WithinRel(50.5)); + } } \ No newline at end of file From 1ddc04895da7effc3a97a107e7013d9a648b21e0 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 30 Jul 2025 18:19:26 +1000 Subject: [PATCH 03/10] Cleanup --- .../src/test/unit_tests/unit_test_camera.cpp | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index 89bec449..59700ff8 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -51,26 +51,6 @@ TEST_CASE("Convert world space to screen space", "[camera][unit]") } } -// Superfluous - tested with rect_on_screen integration -// TEST_CASE("Convert rectangle to screen space", "[camera][rectangle_geometry][graphics][window][integration]") -// { -// // TODO -// } - -// TEST_CASE("Return window as rectangle", "[camera][rectangle_geometry][graphics][window][integration]") -// { -// SECTION("Rectangle from screen") -// { -// // TODO - -// } -// SECTION("Rectangle from window") -// { -// // TODO - -// } -// } - TEST_CASE("Convert screen space to world space", "[camera][unit]") { set_camera_position(point_at(150.0, 150.0)); @@ -157,12 +137,6 @@ TEST_CASE("Check if point is on screen", "[camera][point_geometry][graphics][win close_window(wind); } -// Redundant -// TEST_CASE("Can move camera to coordinates", "[camera][unit]") -// { -// // TODO -// } - TEST_CASE("Can move camera by offset", "[camera][unit]") { move_camera_by(42.0, 100.0); From 89c747e63828e322ca62dbc80fe22eb682663ec3 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 30 Jul 2025 19:21:43 +1000 Subject: [PATCH 04/10] Changed tag names for consistency with source file names --- coresdk/src/test/unit_tests/unit_test_camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index 59700ff8..7e4ca2f1 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -144,7 +144,7 @@ TEST_CASE("Can move camera by offset", "[camera][unit]") REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE("Can center camera on sprite", "[camera][bitmap][sprite][integration]") +TEST_CASE("Can center camera on sprite", "[camera][images][sprites][integration]") { // Create 20x20 square sprite at 50,50 bitmap square_bmp = create_bitmap("square", 20, 20); From 1f4347acb870b94fdcc08c75b80fe92a04177ee2 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 30 Jul 2025 20:30:24 +1000 Subject: [PATCH 05/10] Fix center_camera_on tests Was checking top left coordinates rather than centered camera coordinates --- .../src/test/unit_tests/unit_test_camera.cpp | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index 7e4ca2f1..7c92a573 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -9,14 +9,23 @@ using namespace splashkit_lib; using Catch::Matchers::WithinRel; -TEST_CASE("Camera position correct after moving", "[camera][unit]") +class CameraTest { + public: + CameraTest() + { + set_camera_position(point_at(0.0, 0.0)); + } +}; + + +TEST_CASE_METHOD(CameraTest, "Camera position correct after moving", "[camera][unit]") { set_camera_position(point_at(42.0, 100.0)); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE("Get screen center in world space", "[camera][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "Get screen center in world space", "[camera][graphics][window][integration]") { open_window("Get screen center in world space", 100, 100); point_2d center = screen_center(); @@ -25,7 +34,7 @@ TEST_CASE("Get screen center in world space", "[camera][graphics][window][integr close_current_window(); } -TEST_CASE("Convert world space to screen space", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "Convert world space to screen space", "[camera][unit]") { set_camera_position(point_at(150.0, 150.0)); @@ -51,7 +60,7 @@ TEST_CASE("Convert world space to screen space", "[camera][unit]") } } -TEST_CASE("Convert screen space to world space", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "Convert screen space to world space", "[camera][unit]") { set_camera_position(point_at(150.0, 150.0)); @@ -71,7 +80,7 @@ TEST_CASE("Convert screen space to world space", "[camera][unit]") } } -TEST_CASE("Check if rectangle is on screen", "[camera][rectangle_geometry][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "Check if rectangle is on screen", "[camera][rectangle_geometry][graphics][window][integration]") { window wind = open_window("Check if rectangle is on screen", 100, 100); @@ -104,7 +113,7 @@ TEST_CASE("Check if rectangle is on screen", "[camera][rectangle_geometry][graph close_window(wind); } -TEST_CASE("Check if point is on screen", "[camera][point_geometry][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "Check if point is on screen", "[camera][point_geometry][graphics][window][integration]") { window wind = open_window("Check if point is on screen", 100, 100); @@ -137,32 +146,35 @@ TEST_CASE("Check if point is on screen", "[camera][point_geometry][graphics][win close_window(wind); } -TEST_CASE("Can move camera by offset", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "Can move camera by offset", "[camera][unit]") { move_camera_by(42.0, 100.0); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE("Can center camera on sprite", "[camera][images][sprites][integration]") +TEST_CASE_METHOD(CameraTest, "Can center camera on sprite", "[camera][window][graphics][images][sprites][integration]") { + open_window("Can center camera on sprite", 100, 100); + // Create 20x20 square sprite at 50,50 bitmap square_bmp = create_bitmap("square", 20, 20); sprite square_sprt = create_sprite(square_bmp); - move_sprite_to(square_sprt, 50.0, 50.0); + move_sprite_to(square_sprt, 90.0, 90.0); SECTION("Camera moves to sprite with no offset") { vector_2d offset = vector_to(0.0, 0.0); center_camera_on(square_sprt, offset); - REQUIRE_THAT(camera_x(), WithinRel(50.0)); - REQUIRE_THAT(camera_y(), WithinRel(50.0)); + REQUIRE_THAT(camera_x(), WithinRel(40.0)); + REQUIRE_THAT(camera_y(), WithinRel(40.0)); } SECTION("Camera moves to sprite with offset") { vector_2d offset = vector_to(0.5, 0.5); center_camera_on(square_sprt, offset); - REQUIRE_THAT(camera_x(), WithinRel(50.5)); - REQUIRE_THAT(camera_y(), WithinRel(50.5)); + REQUIRE_THAT(camera_x(), WithinRel(40.5)); + REQUIRE_THAT(camera_y(), WithinRel(40.5)); } + close_current_window(); } \ No newline at end of file From 1065a5201aefc505b9b2ed8de86d92a248f601bf Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 6 Aug 2025 16:35:40 +1000 Subject: [PATCH 06/10] Revert to current tag style --- .../src/test/unit_tests/unit_test_camera.cpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index 7c92a573..1db18cff 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -18,41 +18,41 @@ class CameraTest { }; -TEST_CASE_METHOD(CameraTest, "Camera position correct after moving", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "camera position correct after moving", "[set_camera_position]") { set_camera_position(point_at(42.0, 100.0)); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE_METHOD(CameraTest, "Get screen center in world space", "[camera][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "get screen center in world space", "[screen_center]") { - open_window("Get screen center in world space", 100, 100); + open_window("get screen center in world space", 100, 100); point_2d center = screen_center(); REQUIRE_THAT(center.x, WithinRel(50.0)); REQUIRE_THAT(center.y, WithinRel(50.0)); close_current_window(); } -TEST_CASE_METHOD(CameraTest, "Convert world space to screen space", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "convert world space to screen space", "[to_screen_x][to_screen_y][to_screen][vector_world_to_screen]") { set_camera_position(point_at(150.0, 150.0)); - SECTION("World x to screen space") + SECTION("world x to screen space") { REQUIRE_THAT(to_screen_x(160.0), WithinRel(10.0)); } - SECTION("World y to screen space") + SECTION("world y to screen space") { REQUIRE_THAT(to_screen_y(160.0), WithinRel(10.0)); } - SECTION("World point to screen space") + SECTION("world point to screen space") { point_2d result = to_screen(point_at(160.0, 160.0)); REQUIRE_THAT(result.x, WithinRel(10.0)); REQUIRE_THAT(result.y, WithinRel(10.0)); } - SECTION("World vector to screen space") + SECTION("world vector to screen space") { vector_2d result = vector_world_to_screen(); REQUIRE_THAT(result.x, WithinRel(-150.0)); @@ -60,19 +60,19 @@ TEST_CASE_METHOD(CameraTest, "Convert world space to screen space", "[camera][un } } -TEST_CASE_METHOD(CameraTest, "Convert screen space to world space", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "convert screen space to world space", "[to_world_x][to_world_y][to_world]") { set_camera_position(point_at(150.0, 150.0)); - SECTION("Screen x to world space") + SECTION("screen x to world space") { REQUIRE_THAT(to_world_x(100.0), WithinRel(250.0)); } - SECTION("Screen y to world space") + SECTION("screen y to world space") { REQUIRE_THAT(to_world_y(100.0), WithinRel(250.0)); } - SECTION("Screen point to world space") + SECTION("screen point to world space") { point_2d result = to_world(point_at(100.0, 100.0)); REQUIRE_THAT(result.x, WithinRel(250.0)); @@ -80,19 +80,19 @@ TEST_CASE_METHOD(CameraTest, "Convert screen space to world space", "[camera][un } } -TEST_CASE_METHOD(CameraTest, "Check if rectangle is on screen", "[camera][rectangle_geometry][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "check if rectangle is on screen", "[rect_on_screen][rect_in_window]") { - window wind = open_window("Check if rectangle is on screen", 100, 100); + window wind = open_window("check if rectangle is on screen", 100, 100); SECTION("50x50 rectangle at 0,0") { rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); - SECTION("Rectangle is on screen") + SECTION("rectangle is on screen") { REQUIRE(rect_on_screen(rect)); } - SECTION("Rectangle is in given window") + SECTION("rectangle is in given window") { REQUIRE(rect_in_window(wind, rect)); } @@ -101,11 +101,11 @@ TEST_CASE_METHOD(CameraTest, "Check if rectangle is on screen", "[camera][rectan { rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); - SECTION("Rectangle is off screen") + SECTION("rectangle is off screen") { REQUIRE_FALSE(rect_on_screen(rect)); } - SECTION("Rectangle is out of given window") + SECTION("rectangle is out of given window") { REQUIRE_FALSE(rect_in_window(wind, rect)); } @@ -113,32 +113,32 @@ TEST_CASE_METHOD(CameraTest, "Check if rectangle is on screen", "[camera][rectan close_window(wind); } -TEST_CASE_METHOD(CameraTest, "Check if point is on screen", "[camera][point_geometry][graphics][window][integration]") +TEST_CASE_METHOD(CameraTest, "check if point is on screen", "[point_on_screen][point_in_window]") { - window wind = open_window("Check if point is on screen", 100, 100); + window wind = open_window("check if point is on screen", 100, 100); - SECTION("Point at 50,50") + SECTION("point at 50,50") { point_2d pt = point_at(50.0, 50.0); - SECTION("Point is on screen") + SECTION("point is on screen") { REQUIRE(point_on_screen(pt)); } - SECTION("Point is in given window") + SECTION("point is in given window") { REQUIRE(point_in_window(wind, pt)); } } - SECTION("Point at 100.1,100.1") + SECTION("point at 100.1,100.1") { point_2d pt = point_at(100.1, 100.1); - SECTION("Point is off screen") + SECTION("point is off screen") { REQUIRE_FALSE(point_on_screen(pt)); } - SECTION("Point is out of given window") + SECTION("point is out of given window") { REQUIRE_FALSE(point_in_window(wind, pt)); } @@ -146,30 +146,30 @@ TEST_CASE_METHOD(CameraTest, "Check if point is on screen", "[camera][point_geom close_window(wind); } -TEST_CASE_METHOD(CameraTest, "Can move camera by offset", "[camera][unit]") +TEST_CASE_METHOD(CameraTest, "can move camera by offset", "[move_camera_by]") { move_camera_by(42.0, 100.0); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE_METHOD(CameraTest, "Can center camera on sprite", "[camera][window][graphics][images][sprites][integration]") +TEST_CASE_METHOD(CameraTest, "can center camera on sprite", "[center_camera_on]") { - open_window("Can center camera on sprite", 100, 100); + open_window("can center camera on sprite", 100, 100); // Create 20x20 square sprite at 50,50 bitmap square_bmp = create_bitmap("square", 20, 20); sprite square_sprt = create_sprite(square_bmp); move_sprite_to(square_sprt, 90.0, 90.0); - SECTION("Camera moves to sprite with no offset") + SECTION("camera moves to sprite with no offset") { vector_2d offset = vector_to(0.0, 0.0); center_camera_on(square_sprt, offset); REQUIRE_THAT(camera_x(), WithinRel(40.0)); REQUIRE_THAT(camera_y(), WithinRel(40.0)); } - SECTION("Camera moves to sprite with offset") + SECTION("camera moves to sprite with offset") { vector_2d offset = vector_to(0.5, 0.5); center_camera_on(square_sprt, offset); From 5f97859367d2e7ec43ba321a8c9ecce126565319 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Wed, 6 Aug 2025 16:37:51 +1000 Subject: [PATCH 07/10] Rename and comment test fixture --- .../src/test/unit_tests/unit_test_camera.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index 1db18cff..dec29267 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -9,23 +9,24 @@ using namespace splashkit_lib; using Catch::Matchers::WithinRel; -class CameraTest { +// Fixture to reset camera position for tests +class CameraTestFixture { public: - CameraTest() + CameraTestFixture() { set_camera_position(point_at(0.0, 0.0)); } }; -TEST_CASE_METHOD(CameraTest, "camera position correct after moving", "[set_camera_position]") +TEST_CASE_METHOD(CameraTestFixture, "camera position correct after moving", "[set_camera_position]") { set_camera_position(point_at(42.0, 100.0)); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE_METHOD(CameraTest, "get screen center in world space", "[screen_center]") +TEST_CASE_METHOD(CameraTestFixture, "get screen center in world space", "[screen_center]") { open_window("get screen center in world space", 100, 100); point_2d center = screen_center(); @@ -34,7 +35,7 @@ TEST_CASE_METHOD(CameraTest, "get screen center in world space", "[screen_center close_current_window(); } -TEST_CASE_METHOD(CameraTest, "convert world space to screen space", "[to_screen_x][to_screen_y][to_screen][vector_world_to_screen]") +TEST_CASE_METHOD(CameraTestFixture, "convert world space to screen space", "[to_screen_x][to_screen_y][to_screen][vector_world_to_screen]") { set_camera_position(point_at(150.0, 150.0)); @@ -60,7 +61,7 @@ TEST_CASE_METHOD(CameraTest, "convert world space to screen space", "[to_screen_ } } -TEST_CASE_METHOD(CameraTest, "convert screen space to world space", "[to_world_x][to_world_y][to_world]") +TEST_CASE_METHOD(CameraTestFixture, "convert screen space to world space", "[to_world_x][to_world_y][to_world]") { set_camera_position(point_at(150.0, 150.0)); @@ -80,7 +81,7 @@ TEST_CASE_METHOD(CameraTest, "convert screen space to world space", "[to_world_x } } -TEST_CASE_METHOD(CameraTest, "check if rectangle is on screen", "[rect_on_screen][rect_in_window]") +TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is on screen", "[rect_on_screen][rect_in_window]") { window wind = open_window("check if rectangle is on screen", 100, 100); @@ -113,7 +114,7 @@ TEST_CASE_METHOD(CameraTest, "check if rectangle is on screen", "[rect_on_screen close_window(wind); } -TEST_CASE_METHOD(CameraTest, "check if point is on screen", "[point_on_screen][point_in_window]") +TEST_CASE_METHOD(CameraTestFixture, "check if point is on screen", "[point_on_screen][point_in_window]") { window wind = open_window("check if point is on screen", 100, 100); @@ -146,14 +147,14 @@ TEST_CASE_METHOD(CameraTest, "check if point is on screen", "[point_on_screen][p close_window(wind); } -TEST_CASE_METHOD(CameraTest, "can move camera by offset", "[move_camera_by]") +TEST_CASE_METHOD(CameraTestFixture, "can move camera by offset", "[move_camera_by]") { move_camera_by(42.0, 100.0); REQUIRE_THAT(camera_x(), WithinRel(42.0)); REQUIRE_THAT(camera_y(), WithinRel(100.0)); } -TEST_CASE_METHOD(CameraTest, "can center camera on sprite", "[center_camera_on]") +TEST_CASE_METHOD(CameraTestFixture, "can center camera on sprite", "[center_camera_on]") { open_window("can center camera on sprite", 100, 100); From 05b8a6d1c1c2ec2e16b8f076b8cc8dae03676f0c Mon Sep 17 00:00:00 2001 From: dijidiji Date: Fri, 22 Aug 2025 15:52:21 +1000 Subject: [PATCH 08/10] Add negative coordinate and consecutive movement tests for set_camera_position --- .../src/test/unit_tests/unit_test_camera.cpp | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index dec29267..d31eb46d 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -5,6 +5,7 @@ #include "catch.hpp" #include "camera.h" +#include using namespace splashkit_lib; using Catch::Matchers::WithinRel; @@ -21,9 +22,25 @@ class CameraTestFixture { TEST_CASE_METHOD(CameraTestFixture, "camera position correct after moving", "[set_camera_position]") { - set_camera_position(point_at(42.0, 100.0)); - REQUIRE_THAT(camera_x(), WithinRel(42.0)); - REQUIRE_THAT(camera_y(), WithinRel(100.0)); + SECTION("to positive coordinates") + { + set_camera_position(point_at(42.0, 100.0)); + REQUIRE_THAT(camera_x(), WithinRel(42.0)); + REQUIRE_THAT(camera_y(), WithinRel(100.0)); + } + SECTION("to negative coordinates") + { + set_camera_position(point_at(-42.0, -100.0)); + REQUIRE_THAT(camera_x(), WithinRel(-42.0)); + REQUIRE_THAT(camera_y(), WithinRel(-100.0)); + } + SECTION("consecutive movements") + { + set_camera_position(point_at(-42.0, -100.0)); + set_camera_position(point_at(100.0, 300.0)); + REQUIRE_THAT(camera_x(), WithinRel(100.0)); + REQUIRE_THAT(camera_y(), WithinRel(300.0)); + } } TEST_CASE_METHOD(CameraTestFixture, "get screen center in world space", "[screen_center]") @@ -85,29 +102,49 @@ TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is on screen", "[rect_on { window wind = open_window("check if rectangle is on screen", 100, 100); - SECTION("50x50 rectangle at 0,0") + SECTION("check if on screen") { - rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); - - SECTION("rectangle is on screen") + SECTION("rectangle on screen") { + rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); REQUIRE(rect_on_screen(rect)); } - SECTION("rectangle is in given window") + SECTION("rectangle partially on screen") { - REQUIRE(rect_in_window(wind, rect)); + rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); + REQUIRE(rect_on_screen(rect)); + } + SECTION("rectangle touches border of screen, counts as on screen") + { + rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); + REQUIRE(rect_on_screen(rect)); + } + SECTION("rectangle off screen") + { + rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); + REQUIRE_FALSE(rect_on_screen(rect)); } } - SECTION("50x50 rectangle at 100.1,100.1") + SECTION("check if in window") { - rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); - - SECTION("rectangle is off screen") + SECTION("rectangle in window") { - REQUIRE_FALSE(rect_on_screen(rect)); + rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); + REQUIRE(rect_in_window(wind, rect)); + } + SECTION("rectangle partially in window") + { + rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); + REQUIRE(rect_in_window(wind, rect)); + } + SECTION("rectangle touches border of screen, counts as in window") + { + rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); + REQUIRE(rect_in_window(wind, rect)); } - SECTION("rectangle is out of given window") + SECTION("rectangle out of window") { + rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); REQUIRE_FALSE(rect_in_window(wind, rect)); } } From c4759153f748872b171e48711247a8fac0132dac Mon Sep 17 00:00:00 2001 From: dijidiji Date: Fri, 22 Aug 2025 15:58:11 +1000 Subject: [PATCH 09/10] Add rectangle partially on screen and touching border of screen tests --- .../src/test/unit_tests/unit_test_camera.cpp | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index d31eb46d..da96134e 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -98,55 +98,55 @@ TEST_CASE_METHOD(CameraTestFixture, "convert screen space to world space", "[to_ } } -TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is on screen", "[rect_on_screen][rect_in_window]") +TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is on screen", "[rect_on_screen]") { window wind = open_window("check if rectangle is on screen", 100, 100); - SECTION("check if on screen") + SECTION("rectangle on screen") { - SECTION("rectangle on screen") - { - rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); - REQUIRE(rect_on_screen(rect)); - } - SECTION("rectangle partially on screen") - { - rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); - REQUIRE(rect_on_screen(rect)); - } - SECTION("rectangle touches border of screen, counts as on screen") - { - rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); - REQUIRE(rect_on_screen(rect)); - } - SECTION("rectangle off screen") - { - rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); - REQUIRE_FALSE(rect_on_screen(rect)); - } + rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); + REQUIRE(rect_on_screen(rect)); } - SECTION("check if in window") + SECTION("rectangle partially on screen") { - SECTION("rectangle in window") - { - rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); - REQUIRE(rect_in_window(wind, rect)); - } - SECTION("rectangle partially in window") - { - rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); - REQUIRE(rect_in_window(wind, rect)); - } - SECTION("rectangle touches border of screen, counts as in window") - { - rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); - REQUIRE(rect_in_window(wind, rect)); - } - SECTION("rectangle out of window") - { - rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); - REQUIRE_FALSE(rect_in_window(wind, rect)); - } + rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); + REQUIRE(rect_on_screen(rect)); + } + SECTION("rectangle touches border of screen, counts as off screen") + { + rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); + REQUIRE_FALSE(rect_on_screen(rect)); + } + SECTION("rectangle off screen") + { + rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); + REQUIRE_FALSE(rect_on_screen(rect)); + } +} + +TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is in window", "[rect_in_window]") +{ + window wind = open_window("check if rectangle is in window", 100, 100); + + SECTION("rectangle in window") + { + rectangle rect = rectangle_from(0.0, 0.0, 50.0, 50.0); + REQUIRE(rect_in_window(wind, rect)); + } + SECTION("rectangle partially in window") + { + rectangle rect = rectangle_from(75.0, 75.0, 50.0, 50.0); + REQUIRE(rect_in_window(wind, rect)); + } + SECTION("rectangle touches border of screen, counts as out of window") + { + rectangle rect = rectangle_from(100.0, 100.0, 50.0, 50.0); + REQUIRE_FALSE(rect_in_window(wind, rect)); + } + SECTION("rectangle out of window") + { + rectangle rect = rectangle_from(100.1, 100.1, 50.0, 50.0); + REQUIRE_FALSE(rect_in_window(wind, rect)); } close_window(wind); } From 9af3978dded6c1c808c595d4f35c375fcb3fe775 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Fri, 22 Aug 2025 16:08:19 +1000 Subject: [PATCH 10/10] Add tests for if a point is on the edge of the screen --- .../src/test/unit_tests/unit_test_camera.cpp | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_camera.cpp b/coresdk/src/test/unit_tests/unit_test_camera.cpp index da96134e..24c165ec 100644 --- a/coresdk/src/test/unit_tests/unit_test_camera.cpp +++ b/coresdk/src/test/unit_tests/unit_test_camera.cpp @@ -151,35 +151,46 @@ TEST_CASE_METHOD(CameraTestFixture, "check if rectangle is in window", "[rect_in close_window(wind); } -TEST_CASE_METHOD(CameraTestFixture, "check if point is on screen", "[point_on_screen][point_in_window]") +TEST_CASE_METHOD(CameraTestFixture, "check if point is on screen", "[point_on_screen]") { window wind = open_window("check if point is on screen", 100, 100); - SECTION("point at 50,50") + SECTION("point is on screen") { point_2d pt = point_at(50.0, 50.0); - - SECTION("point is on screen") - { - REQUIRE(point_on_screen(pt)); - } - SECTION("point is in given window") - { - REQUIRE(point_in_window(wind, pt)); - } + REQUIRE(point_on_screen(pt)); + } + SECTION("point is on edge of screen, counts as on screen") + { + point_2d pt = point_at(100.0, 100.0); + REQUIRE(point_on_screen(pt)); } - SECTION("point at 100.1,100.1") + SECTION("point is off screen") { point_2d pt = point_at(100.1, 100.1); + REQUIRE_FALSE(point_on_screen(pt)); + } + close_window(wind); +} - SECTION("point is off screen") - { - REQUIRE_FALSE(point_on_screen(pt)); - } - SECTION("point is out of given window") - { - REQUIRE_FALSE(point_in_window(wind, pt)); - } +TEST_CASE_METHOD(CameraTestFixture, "check if point is in window", "[point_in_window]") +{ + window wind = open_window("check if point is in window", 100, 100); + + SECTION("point is in window") + { + point_2d pt = point_at(50.0, 50.0); + REQUIRE(point_in_window(wind, pt)); + } + SECTION("point is on edge of screen, counts as in window") + { + point_2d pt = point_at(100.0, 100.0); + REQUIRE(point_in_window(wind, pt)); + } + SECTION("point is out of window") + { + point_2d pt = point_at(100.1, 100.1); + REQUIRE_FALSE(point_in_window(wind, pt)); } close_window(wind); }