From e46663cf38356201e8340108d9e6847b3ea14014 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Wed, 18 Sep 2024 11:45:40 -0400 Subject: [PATCH] Add tests for `sfRect` --- test/CMakeLists.txt | 7 +++++ test/Graphics/Rect.test.cpp | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/Graphics/Rect.test.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index baf6c1e..ee7d2f9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,6 +44,13 @@ target_link_libraries(test-csfml-window PRIVATE csfml-window Catch2::Catch2WithM set_target_warnings(test-csfml-window) catch_discover_tests(test-csfml-window) +add_executable(test-csfml-graphics + Graphics/Rect.test.cpp +) +target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain) +set_target_warnings(test-csfml-graphics) +catch_discover_tests(test-csfml-graphics) + add_executable(test-csfml-network Network/Ftp.test.cpp Network/Http.test.cpp diff --git a/test/Graphics/Rect.test.cpp b/test/Graphics/Rect.test.cpp new file mode 100644 index 0000000..27e06a2 --- /dev/null +++ b/test/Graphics/Rect.test.cpp @@ -0,0 +1,56 @@ +#include + +#include + +TEST_CASE("[Graphics] sfRect") +{ + SECTION("Construction") + { + SECTION("float") + { + const sfFloatRect rect{}; + CHECK(rect.position.x == 0.f); + CHECK(rect.position.y == 0.f); + CHECK(rect.size.x == 0.f); + CHECK(rect.size.y == 0.f); + } + + SECTION("int") + { + const sfFloatRect rect{}; + CHECK(rect.position.x == 0); + CHECK(rect.position.y == 0); + CHECK(rect.size.x == 0); + CHECK(rect.size.y == 0); + } + } + + SECTION("contains(Vector2)") + { + SECTION("float") + { + const sfFloatRect rect{{0, 0}, {10, 10}}; + CHECK(sfFloatRect_contains(&rect, {0, 0})); + CHECK(sfFloatRect_contains(&rect, {9, 0})); + CHECK(sfFloatRect_contains(&rect, {0, 9})); + CHECK(sfFloatRect_contains(&rect, {9, 9})); + CHECK(!sfFloatRect_contains(&rect, {9, 10})); + CHECK(!sfFloatRect_contains(&rect, {10, 9})); + CHECK(!sfFloatRect_contains(&rect, {10, 10})); + CHECK(!sfFloatRect_contains(&rect, {15, 15})); + } + + SECTION("int") + { + const sfIntRect rect{{0, 0}, {10, 10}}; + CHECK(sfIntRect_contains(&rect, {0, 0})); + CHECK(sfIntRect_contains(&rect, {9, 0})); + CHECK(sfIntRect_contains(&rect, {0, 9})); + CHECK(sfIntRect_contains(&rect, {9, 9})); + CHECK(!sfIntRect_contains(&rect, {9, 10})); + CHECK(!sfIntRect_contains(&rect, {10, 9})); + CHECK(!sfIntRect_contains(&rect, {10, 10})); + CHECK(!sfIntRect_contains(&rect, {15, 15})); + } + } +}