pacman/test/testGhost.cpp

78 lines
1.6 KiB
C++
Raw Normal View History

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