pacman/test/testGhost.cpp
2021-09-21 16:34:26 +02:00

77 lines
1.6 KiB
C++

#include "Blinky.hpp"
#include "Clyde.hpp"
#include "Inky.hpp"
#include "Pinky.hpp"
#include <catch2/catch.hpp>
template<typename T>
static void ghostInitTest(const T & ghost, double x, double y) {
const pacman::Position pos{ x, y };
REQUIRE(ghost.position() == pos);
const pacman::GridPosition gridPos = pacman::positionToGridPosition(pos);
REQUIRE(ghost.positionInGrid() == gridPos);
REQUIRE_FALSE(ghost.isEyes());
REQUIRE_FALSE(ghost.isFrightened());
}
TEST_CASE("Ghosts start in the correct position", "[ghosts]") {
pacman::Blinky blinky;
ghostInitTest(blinky, 13.5, 11);
pacman::Clyde clyde;
ghostInitTest(clyde, 15.5, 14);
pacman::Inky inky;
ghostInitTest(inky, 13.5, 14);
pacman::Pinky pinky;
ghostInitTest(pinky, 11.5, 14);
}
template<typename T>
static void ghostFrightenTest(T & ghost) {
REQUIRE_FALSE(ghost.isFrightened());
ghost.frighten();
REQUIRE(ghost.isFrightened());
ghost.reset();
REQUIRE_FALSE(ghost.isFrightened());
}
TEST_CASE("Ghosts are frighten", "[ghosts]") {
pacman::Blinky blinky;
ghostFrightenTest(blinky);
pacman::Clyde clyde;
ghostFrightenTest(clyde);
pacman::Inky inky;
ghostFrightenTest(inky);
pacman::Pinky pinky;
ghostFrightenTest(pinky);
}
template<typename T>
static void ghostDeadTest(T & ghost) {
REQUIRE_FALSE(ghost.isEyes());
ghost.die();
REQUIRE(ghost.isEyes());
ghost.reset();
REQUIRE_FALSE(ghost.isEyes());
}
TEST_CASE("Ghosts can die", "[ghosts]") {
pacman::Blinky blinky;
ghostDeadTest(blinky);
pacman::Clyde clyde;
ghostDeadTest(clyde);
pacman::Inky inky;
ghostDeadTest(inky);
pacman::Pinky pinky;
ghostDeadTest(pinky);
}