2021-09-06 13:54:19 +00:00
|
|
|
#include "Position.hpp"
|
2021-09-11 08:09:59 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2021-09-06 13:54:19 +00:00
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Position are properly initialized", "[positions]") {
|
2021-09-06 14:24:30 +00:00
|
|
|
pacman::Position pos;
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(pos.x == Approx(0.0));
|
|
|
|
REQUIRE(pos.y == Approx(0.0));
|
2021-09-06 14:24:30 +00:00
|
|
|
|
|
|
|
pacman::Position pos2{ 10.0, 20.0 };
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(pos2.x == Approx(10.0));
|
|
|
|
REQUIRE(pos2.y == Approx(20.0));
|
2021-09-06 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("GridPosition are properly initialized", "[positions]") {
|
2021-09-06 14:24:30 +00:00
|
|
|
pacman::GridPosition gridPos{ 10, 20 };
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(gridPos.x == 10);
|
|
|
|
REQUIRE(gridPos.y == 20);
|
2021-09-06 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Position converts to GridPosition", "[positions]") {
|
2021-09-06 14:24:30 +00:00
|
|
|
pacman::Position pos{ 10.0, 20.0 };
|
|
|
|
const auto gridPos = pacman::positionToGridPosition(pos);
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(gridPos.x == 10);
|
|
|
|
REQUIRE(gridPos.y == 20);
|
2021-09-06 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("GridPosition converts to Position", "[positions]") {
|
2021-09-06 14:24:30 +00:00
|
|
|
pacman::GridPosition gridPos{ 10, 20 };
|
|
|
|
const auto pos = pacman::gridPositionToPosition(gridPos);
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(pos.x == Approx(10.0));
|
|
|
|
REQUIRE(pos.y == Approx(20.0));
|
2021-09-06 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Positions compare equal", "[positions]") {
|
2021-09-06 14:24:30 +00:00
|
|
|
pacman::Position pos1{ 10.0, 20.0 };
|
|
|
|
pacman::Position pos2{ 10.0, 20.0 };
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(pos1 == pos2);
|
2021-09-06 14:24:30 +00:00
|
|
|
|
|
|
|
pacman::Position pos3{ 9.9, 19.9 };
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(pos1 == pos3);
|
2021-09-06 14:24:30 +00:00
|
|
|
|
|
|
|
pos3.x += 0.1;
|
|
|
|
pos3.y += 0.1;
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(pos1 == pos3);
|
2021-09-06 13:54:19 +00:00
|
|
|
}
|