2014-08-26 15:52:37 +08:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
2018-08-19 07:30:53 +08:00
|
|
|
#include "TestUtilities/System.hpp"
|
2014-08-26 15:52:37 +08:00
|
|
|
|
|
|
|
// Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations.
|
|
|
|
|
2015-04-29 04:46:24 +08:00
|
|
|
TEST_CASE("sf::Vector2 class template", "[system]")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Construction")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Default constructor")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
sf::Vector2i vector;
|
2014-08-26 15:52:37 +08:00
|
|
|
CHECK(vector.x == 0);
|
|
|
|
CHECK(vector.y == 0);
|
|
|
|
}
|
|
|
|
|
2018-08-19 22:14:54 +08:00
|
|
|
SECTION("(x, y) coordinate constructor")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
sf::Vector2i vector(1, 2);
|
2014-08-26 15:52:37 +08:00
|
|
|
CHECK(vector.x == 1);
|
|
|
|
CHECK(vector.y == 2);
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Conversion constructor")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
sf::Vector2f sourceVector(1.0f, 2.0f);
|
2014-08-26 15:52:37 +08:00
|
|
|
sf::Vector2i vector(sourceVector);
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(vector.x == static_cast<int>(sourceVector.x));
|
|
|
|
CHECK(vector.y == static_cast<int>(sourceVector.y));
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Unary operations")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("-vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
sf::Vector2i vector(1, 2);
|
2014-08-26 15:52:37 +08:00
|
|
|
sf::Vector2i negatedVector = -vector;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(negatedVector.x == -1);
|
|
|
|
CHECK(negatedVector.y == -2);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Arithmetic operations between two vectors")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i firstVector(2, 5);
|
|
|
|
sf::Vector2i secondVector(8, 3);
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector += vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
firstVector += secondVector;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(firstVector.x == 10);
|
|
|
|
CHECK(firstVector.y == 8);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector -= vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
firstVector -= secondVector;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(firstVector.x == -6);
|
|
|
|
CHECK(firstVector.y == 2);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector + vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i result = firstVector + secondVector;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(result.x == 10);
|
|
|
|
CHECK(result.y == 8);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector - vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i result = firstVector - secondVector;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(result.x == -6);
|
|
|
|
CHECK(result.y == 2);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Arithmetic operations between vector and scalar value")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i vector(26, 12);
|
2015-04-26 21:24:49 +08:00
|
|
|
int scalar = 2;
|
2014-08-26 15:52:37 +08:00
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector * scalar")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i result = vector * scalar;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(result.x == 52);
|
|
|
|
CHECK(result.y == 24);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("scalar * vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
sf::Vector2i result = scalar * vector;
|
2014-08-26 15:52:37 +08:00
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(result.x == 52);
|
|
|
|
CHECK(result.y == 24);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector *= scalar")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
vector *= scalar;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(vector.x == 52);
|
|
|
|
CHECK(vector.y == 24);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector / scalar")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i result = vector / scalar;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(result.x == 13);
|
|
|
|
CHECK(result.y == 6);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector /= scalar")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
vector /= scalar;
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(vector.x == 13);
|
|
|
|
CHECK(vector.y == 6);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("Comparison operations (two equal and one different vector)")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
|
|
|
sf::Vector2i firstEqualVector(1, 5);
|
|
|
|
sf::Vector2i secondEqualVector(1, 5);
|
|
|
|
sf::Vector2i differentVector(6, 9);
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector == vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(firstEqualVector == secondEqualVector);
|
|
|
|
CHECK_FALSE(firstEqualVector == differentVector);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:24:49 +08:00
|
|
|
SECTION("vector != vector")
|
2014-08-26 15:52:37 +08:00
|
|
|
{
|
2015-04-26 21:24:49 +08:00
|
|
|
CHECK(firstEqualVector != differentVector);
|
|
|
|
CHECK_FALSE(firstEqualVector != secondEqualVector);
|
2014-08-26 15:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|