From 3925139f4d1ddc3a5d6cdd62c5d3768c695de6e8 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 24 Jun 2022 17:00:59 -0600 Subject: [PATCH] Improve test coverage of `sf::Rect` --- test/Graphics/Rect.cpp | 64 +++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/test/Graphics/Rect.cpp b/test/Graphics/Rect.cpp index 617c069e..71319173 100644 --- a/test/Graphics/Rect.cpp +++ b/test/Graphics/Rect.cpp @@ -50,24 +50,21 @@ TEST_CASE("sf::Rect class template - [graphics]") } } - SUBCASE("Containment") + SUBCASE("contains(Vector2)") { - SUBCASE("contains(Vector2)") - { - sf::IntRect rectangle({0, 0}, {10, 10}); + sf::IntRect rectangle({0, 0}, {10, 10}); - CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true); - CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true); - CHECK(rectangle.contains(sf::Vector2i(0, 9)) == true); - CHECK(rectangle.contains(sf::Vector2i(9, 9)) == true); - CHECK(rectangle.contains(sf::Vector2i(9, 10)) == false); - CHECK(rectangle.contains(sf::Vector2i(10, 9)) == false); - CHECK(rectangle.contains(sf::Vector2i(10, 10)) == false); - CHECK(rectangle.contains(sf::Vector2i(15, 15)) == false); - } + CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true); + CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true); + CHECK(rectangle.contains(sf::Vector2i(0, 9)) == true); + CHECK(rectangle.contains(sf::Vector2i(9, 9)) == true); + CHECK(rectangle.contains(sf::Vector2i(9, 10)) == false); + CHECK(rectangle.contains(sf::Vector2i(10, 9)) == false); + CHECK(rectangle.contains(sf::Vector2i(10, 10)) == false); + CHECK(rectangle.contains(sf::Vector2i(15, 15)) == false); } - SUBCASE("Intersection") + SUBCASE("findIntersection()") { const sf::IntRect rectangle({0, 0}, {10, 10}); const sf::IntRect intersectingRectangle({5, 5}, {10, 10}); @@ -84,13 +81,40 @@ TEST_CASE("sf::Rect class template - [graphics]") CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle)); } - SUBCASE("Comparison operations") + SUBCASE("getPosition()") { - sf::IntRect firstRectangle({1, 3}, {2, 5}); - sf::IntRect secondRectangle({1, 3}, {2, 5}); - sf::IntRect differentRectangle({3, 1}, {5, 2}); + CHECK(sf::IntRect({}, {}).getPosition() == sf::Vector2i()); + CHECK(sf::IntRect({1, 2}, {3, 4}).getPosition() == sf::Vector2i(1, 2)); + } - CHECK(firstRectangle == secondRectangle); - CHECK(firstRectangle != differentRectangle); + SUBCASE("getSize()") + { + CHECK(sf::IntRect({}, {}).getSize() == sf::Vector2i()); + CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4)); + } + + SUBCASE("Operators") + { + SUBCASE("operator==") + { + CHECK(sf::IntRect() == sf::IntRect()); + CHECK(sf::IntRect({1, 3}, {2, 5}) == sf::IntRect({1, 3}, {2, 5})); + + CHECK_FALSE(sf::IntRect({1, 0}, {0, 0}) == sf::IntRect({0, 0}, {0, 0})); + CHECK_FALSE(sf::IntRect({0, 1}, {0, 0}) == sf::IntRect({0, 0}, {0, 0})); + CHECK_FALSE(sf::IntRect({0, 0}, {1, 0}) == sf::IntRect({0, 0}, {0, 0})); + CHECK_FALSE(sf::IntRect({0, 0}, {0, 1}) == sf::IntRect({0, 0}, {0, 0})); + } + + SUBCASE("operator!=") + { + CHECK(sf::IntRect({1, 0}, {0, 0}) != sf::IntRect({0, 0}, {0, 0})); + CHECK(sf::IntRect({0, 1}, {0, 0}) != sf::IntRect({0, 0}, {0, 0})); + CHECK(sf::IntRect({0, 0}, {1, 0}) != sf::IntRect({0, 0}, {0, 0})); + CHECK(sf::IntRect({0, 0}, {0, 1}) != sf::IntRect({0, 0}, {0, 0})); + + CHECK_FALSE(sf::IntRect() != sf::IntRect()); + CHECK_FALSE(sf::IntRect({1, 3}, {2, 5}) != sf::IntRect({1, 3}, {2, 5})); + } } }