diff --git a/test/src/Vector2.cpp b/test/src/Vector2.cpp index 1a977592..92fde45b 100644 --- a/test/src/Vector2.cpp +++ b/test/src/Vector2.cpp @@ -3,220 +3,146 @@ // Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations. -SCENARIO("Constructing sf::Vector2") +TEST_CASE("sf::Vector2 class") { - WHEN("default constructor is used") + SECTION("Construction") { - sf::Vector2i vector; - - THEN("x and y are 0") + SECTION("Default constructor") { + sf::Vector2i vector; CHECK(vector.x == 0); CHECK(vector.y == 0); } - } - WHEN("x, y constructor is used") - { - sf::Vector2i vector(1, 2); - - THEN("x and y are set accordingly") + SECTION("(x,y) coordinate constructor") { + sf::Vector2i vector(1, 2); CHECK(vector.x == 1); CHECK(vector.y == 2); } - } - GIVEN("a vector of a different type") - { - sf::Vector2f sourceVector(1.0f, 2.0f); - - WHEN("a vector is constructed from the another vector") + SECTION("Conversion constructor") { + sf::Vector2f sourceVector(1.0f, 2.0f); sf::Vector2i vector(sourceVector); - THEN("x and y are equal to the source vector's elements") - { - CHECK(vector.x == static_cast(sourceVector.x)); - CHECK(vector.y == static_cast(sourceVector.y)); - } + CHECK(vector.x == static_cast(sourceVector.x)); + CHECK(vector.y == static_cast(sourceVector.y)); } } -} -SCENARIO("sf::Vector2 algebra") -{ - GIVEN("a vector with x and y != 0") + SECTION("Unary operations") { - sf::Vector2i vector(1, 2); - - WHEN("the vector is negated") + SECTION("-vector") { + sf::Vector2i vector(1, 2); sf::Vector2i negatedVector = -vector; - THEN("x and y are negated") - { - CHECK(negatedVector.x == -1); - CHECK(negatedVector.y == -2); - } + CHECK(negatedVector.x == -1); + CHECK(negatedVector.y == -2); } } - GIVEN("two different vectors with x and y != 0") + SECTION("Arithmetic operations between two vectors") { sf::Vector2i firstVector(2, 5); sf::Vector2i secondVector(8, 3); - WHEN("one vector is increased by another one") + SECTION("vector += vector") { firstVector += secondVector; - THEN("the first operand's x and y are increased by the second one's") - { - CHECK(firstVector.x == 10); - CHECK(firstVector.y == 8); - } + CHECK(firstVector.x == 10); + CHECK(firstVector.y == 8); } - WHEN("one vector is decreased by another one") + SECTION("vector -= vector") { firstVector -= secondVector; - THEN("the first operand's x and y are decreased by the second one's") - { - CHECK(firstVector.x == -6); - CHECK(firstVector.y == 2); - } + CHECK(firstVector.x == -6); + CHECK(firstVector.y == 2); } - WHEN("two vectors are summed") + SECTION("vector + vector") { sf::Vector2i result = firstVector + secondVector; - THEN("the result vector's x and y are the sum of the vectors' x and y") - { - CHECK(result.x == 10); - CHECK(result.y == 8); - } + CHECK(result.x == 10); + CHECK(result.y == 8); } - WHEN("one vector is subtracted from another one") + SECTION("vector - vector") { sf::Vector2i result = firstVector - secondVector; - THEN("the result vector's x and y are the difference of the vectors' x and y") - { - CHECK(result.x == -6); - CHECK(result.y == 2); - } + CHECK(result.x == -6); + CHECK(result.y == 2); } } - GIVEN("a vector with x and y != 0 and a scalar value") + SECTION("Arithmetic operations between vector and scalar value") { sf::Vector2i vector(26, 12); - int scalar(2); + int scalar = 2; - WHEN("a vector is multiplied by a scalar") + SECTION("vector * scalar") { sf::Vector2i result = vector * scalar; - THEN("the result vector's x and y are the product with the scalar") - { - CHECK(result.x == 52); - CHECK(result.y == 24); - } + CHECK(result.x == 52); + CHECK(result.y == 24); } - WHEN("a scalar is multiplied by a vector") + SECTION("scalar * vector") { - sf::Vector2i result = scalar * vector ; + sf::Vector2i result = scalar * vector; - THEN("the result vector's x and y are the product with the scalar") - { - CHECK(result.x == 52); - CHECK(result.y == 24); - } + CHECK(result.x == 52); + CHECK(result.y == 24); } - WHEN("a vector is multiplied by a scalar in itself") + SECTION("vector *= scalar") { vector *= scalar; - THEN("the vector's x and y are the product with the scalar") - { - CHECK(vector.x == 52); - CHECK(vector.y == 24); - } + CHECK(vector.x == 52); + CHECK(vector.y == 24); } - WHEN("a vector is divided by a scalar") + SECTION("vector / scalar") { sf::Vector2i result = vector / scalar; - THEN("the result vector's x and y are the division with the scalar") - { - CHECK(result.x == 13); - CHECK(result.y == 6); - } + CHECK(result.x == 13); + CHECK(result.y == 6); } - WHEN("a vector is divided by a scalar in itself") + SECTION("vector /= scalar") { vector /= scalar; - THEN("the vector's x and y are the division with the scalar") - { - CHECK(vector.x == 13); - CHECK(vector.y == 6); - } + CHECK(vector.x == 13); + CHECK(vector.y == 6); } } - GIVEN("3 vectors, where two are equal") + SECTION("Comparison operations (two equal and one different vector)") { sf::Vector2i firstEqualVector(1, 5); sf::Vector2i secondEqualVector(1, 5); sf::Vector2i differentVector(6, 9); - WHEN("equal vectors are tested for equality") + SECTION("vector == vector") { - bool equal = (firstEqualVector == secondEqualVector); - - THEN("the result is true") - { - CHECK(equal == true); - } + CHECK(firstEqualVector == secondEqualVector); + CHECK_FALSE(firstEqualVector == differentVector); } - WHEN("different vectors are tested for equality") + SECTION("vector != vector") { - bool equal = (firstEqualVector == differentVector); - - THEN("the result is false") - { - CHECK(equal == false); - } - } - - WHEN("equal vectors are tested for inequality") - { - bool equal = (firstEqualVector != secondEqualVector); - - THEN("the result is false") - { - CHECK(equal == false); - } - } - - WHEN("different vectors are tested for inequality") - { - bool equal = (firstEqualVector != differentVector); - - THEN("the result is true") - { - CHECK(equal == true); - } + CHECK(firstEqualVector != differentVector); + CHECK_FALSE(firstEqualVector != secondEqualVector); } } }