From 65c0a8183c003fbbca98c29163b9b7424c0d36cc Mon Sep 17 00:00:00 2001 From: kimci86 Date: Sat, 4 May 2024 15:01:52 +0200 Subject: [PATCH] Simplify Rect unit tests --- test/Graphics/Rect.test.cpp | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/test/Graphics/Rect.test.cpp b/test/Graphics/Rect.test.cpp index c17ec462b..384d26989 100644 --- a/test/Graphics/Rect.test.cpp +++ b/test/Graphics/Rect.test.cpp @@ -22,19 +22,8 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) SECTION("Default constructor") { constexpr sf::Rect rectangle; - STATIC_CHECK(rectangle.position.x == 0); - STATIC_CHECK(rectangle.position.y == 0); - STATIC_CHECK(rectangle.size.x == 0); - STATIC_CHECK(rectangle.size.y == 0); - } - - SECTION("(left, top, width, height) constructor") - { - constexpr sf::Rect rectangle({1, 2}, {3, 4}); - STATIC_CHECK(rectangle.position.x == 1); - STATIC_CHECK(rectangle.position.y == 2); - STATIC_CHECK(rectangle.size.x == 3); - STATIC_CHECK(rectangle.size.y == 4); + STATIC_CHECK(rectangle.position == sf::Vector2()); + STATIC_CHECK(rectangle.size == sf::Vector2()); } SECTION("(Vector2, Vector2) constructor") @@ -43,10 +32,8 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr sf::Vector2 dimension(3, 4); constexpr sf::Rect rectangle(position, dimension); - STATIC_CHECK(rectangle.position.x == 1); - STATIC_CHECK(rectangle.position.y == 2); - STATIC_CHECK(rectangle.size.x == 3); - STATIC_CHECK(rectangle.size.y == 4); + STATIC_CHECK(rectangle.position == position); + STATIC_CHECK(rectangle.size == dimension); } SECTION("Conversion constructor") @@ -54,10 +41,8 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f}); constexpr sf::IntRect rectangle(sourceRectangle); - STATIC_CHECK(rectangle.position.x == static_cast(sourceRectangle.position.x)); - STATIC_CHECK(rectangle.position.y == static_cast(sourceRectangle.position.y)); - STATIC_CHECK(rectangle.size.x == static_cast(sourceRectangle.size.x)); - STATIC_CHECK(rectangle.size.y == static_cast(sourceRectangle.size.y)); + STATIC_CHECK(rectangle.position == sf::Vector2i(1, 2)); + STATIC_CHECK(rectangle.size == sf::Vector2i(3, 4)); } } @@ -82,10 +67,7 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr auto intersectionResult = rectangle.findIntersection(intersectingRectangle); STATIC_REQUIRE(intersectionResult.has_value()); - STATIC_CHECK(intersectionResult->position.x == 5); - STATIC_CHECK(intersectionResult->position.y == 5); - STATIC_CHECK(intersectionResult->size.x == 5); - STATIC_CHECK(intersectionResult->size.y == 5); + STATIC_CHECK(*intersectionResult == sf::Rect({5, 5}, {5, 5})); constexpr sf::Rect nonIntersectingRectangle({-5, -5}, {5, 5}); STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value());