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-10 11:57:01 +00:00
|
|
|
static void ghostInitHelper(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;
|
|
|
|
ghostInitHelper(blinky, 13.5, 11);
|
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
|
|
|
ghostInitHelper(clyde, 15.5, 14);
|
|
|
|
|
|
|
|
pacman::Inky inky;
|
|
|
|
ghostInitHelper(inky, 13.5, 14);
|
2021-09-10 11:57:01 +00:00
|
|
|
|
2021-09-07 09:25:45 +00:00
|
|
|
pacman::Pinky pinky;
|
|
|
|
ghostInitHelper(pinky, 11.5, 14);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2021-09-10 11:57:01 +00:00
|
|
|
static void ghostFrightenHelper(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;
|
|
|
|
ghostFrightenHelper(blinky);
|
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
|
|
|
ghostFrightenHelper(clyde);
|
|
|
|
|
|
|
|
pacman::Inky inky;
|
|
|
|
ghostFrightenHelper(inky);
|
|
|
|
|
|
|
|
pacman::Pinky pinky;
|
|
|
|
ghostFrightenHelper(pinky);
|
2021-09-07 13:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static void ghostDeadHelper(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;
|
|
|
|
ghostDeadHelper(blinky);
|
|
|
|
|
|
|
|
pacman::Clyde clyde;
|
|
|
|
ghostDeadHelper(clyde);
|
|
|
|
|
|
|
|
pacman::Inky inky;
|
|
|
|
ghostDeadHelper(inky);
|
|
|
|
|
|
|
|
pacman::Pinky pinky;
|
|
|
|
ghostDeadHelper(pinky);
|
|
|
|
}
|