2021-09-07 09:25:45 +00:00
|
|
|
#include "Blinky.hpp"
|
|
|
|
#include "Clyde.hpp"
|
|
|
|
#include "Inky.hpp"
|
|
|
|
#include "Pinky.hpp"
|
2021-09-11 08:09:59 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
2021-09-07 09:25:45 +00:00
|
|
|
template<typename T>
|
2021-09-21 14:34:26 +00:00
|
|
|
static void ghostInitTest(const T & ghost, double x, double y) {
|
2021-09-07 09:25:45 +00:00
|
|
|
const pacman::Position pos{ x, y };
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(ghost.position() == pos);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
const pacman::GridPosition gridPos = pacman::positionToGridPosition(pos);
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(ghost.positionInGrid() == gridPos);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(ghost.isEyes());
|
|
|
|
REQUIRE_FALSE(ghost.isFrightened());
|
2021-09-07 09:25:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Ghosts start in the correct position", "[ghosts]") {
|
2021-09-07 09:25:45 +00:00
|
|
|
pacman::Blinky blinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostInitTest(blinky, 13.5, 11);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostInitTest(clyde, 15.5, 14);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
pacman::Inky inky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostInitTest(inky, 13.5, 14);
|
2021-09-10 11:57:01 +00:00
|
|
|
|
2021-09-07 09:25:45 +00:00
|
|
|
pacman::Pinky pinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostInitTest(pinky, 11.5, 14);
|
2021-09-07 09:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2021-09-21 14:34:26 +00:00
|
|
|
static void ghostFrightenTest(T & ghost) {
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(ghost.isFrightened());
|
2021-09-07 09:25:45 +00:00
|
|
|
ghost.frighten();
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(ghost.isFrightened());
|
2021-09-07 09:25:45 +00:00
|
|
|
ghost.reset();
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(ghost.isFrightened());
|
2021-09-07 09:25:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Ghosts are frighten", "[ghosts]") {
|
2021-09-07 09:25:45 +00:00
|
|
|
pacman::Blinky blinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostFrightenTest(blinky);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostFrightenTest(clyde);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
pacman::Inky inky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostFrightenTest(inky);
|
2021-09-07 09:25:45 +00:00
|
|
|
|
|
|
|
pacman::Pinky pinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostFrightenTest(pinky);
|
2021-09-07 13:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2021-09-21 14:34:26 +00:00
|
|
|
static void ghostDeadTest(T & ghost) {
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(ghost.isEyes());
|
2021-09-07 13:30:48 +00:00
|
|
|
ghost.die();
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE(ghost.isEyes());
|
2021-09-07 13:30:48 +00:00
|
|
|
ghost.reset();
|
2021-09-11 08:09:59 +00:00
|
|
|
REQUIRE_FALSE(ghost.isEyes());
|
2021-09-07 13:30:48 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 08:09:59 +00:00
|
|
|
TEST_CASE("Ghosts can die", "[ghosts]") {
|
2021-09-07 13:30:48 +00:00
|
|
|
pacman::Blinky blinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostDeadTest(blinky);
|
2021-09-07 13:30:48 +00:00
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostDeadTest(clyde);
|
2021-09-07 13:30:48 +00:00
|
|
|
|
|
|
|
pacman::Inky inky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostDeadTest(inky);
|
2021-09-07 13:30:48 +00:00
|
|
|
|
|
|
|
pacman::Pinky pinky;
|
2021-09-21 14:34:26 +00:00
|
|
|
ghostDeadTest(pinky);
|
2021-09-07 13:30:48 +00:00
|
|
|
}
|