Adding pellet test and renaming helpers.
This commit is contained in:
parent
4b9f88013d
commit
125c55f176
2 changed files with 60 additions and 16 deletions
|
@ -4,9 +4,8 @@
|
|||
#include "Pinky.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
||||
template<typename T>
|
||||
static void ghostInitHelper(const T & ghost, double x, double y) {
|
||||
static void ghostInitTest(const T & ghost, double x, double y) {
|
||||
const pacman::Position pos{ x, y };
|
||||
REQUIRE(ghost.position() == pos);
|
||||
|
||||
|
@ -19,20 +18,20 @@ static void ghostInitHelper(const T & ghost, double x, double y) {
|
|||
|
||||
TEST_CASE("Ghosts start in the correct position", "[ghosts]") {
|
||||
pacman::Blinky blinky;
|
||||
ghostInitHelper(blinky, 13.5, 11);
|
||||
ghostInitTest(blinky, 13.5, 11);
|
||||
|
||||
pacman::Clyde clyde;
|
||||
ghostInitHelper(clyde, 15.5, 14);
|
||||
ghostInitTest(clyde, 15.5, 14);
|
||||
|
||||
pacman::Inky inky;
|
||||
ghostInitHelper(inky, 13.5, 14);
|
||||
ghostInitTest(inky, 13.5, 14);
|
||||
|
||||
pacman::Pinky pinky;
|
||||
ghostInitHelper(pinky, 11.5, 14);
|
||||
ghostInitTest(pinky, 11.5, 14);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void ghostFrightenHelper(T & ghost) {
|
||||
static void ghostFrightenTest(T & ghost) {
|
||||
REQUIRE_FALSE(ghost.isFrightened());
|
||||
ghost.frighten();
|
||||
REQUIRE(ghost.isFrightened());
|
||||
|
@ -42,20 +41,20 @@ static void ghostFrightenHelper(T & ghost) {
|
|||
|
||||
TEST_CASE("Ghosts are frighten", "[ghosts]") {
|
||||
pacman::Blinky blinky;
|
||||
ghostFrightenHelper(blinky);
|
||||
ghostFrightenTest(blinky);
|
||||
|
||||
pacman::Clyde clyde;
|
||||
ghostFrightenHelper(clyde);
|
||||
ghostFrightenTest(clyde);
|
||||
|
||||
pacman::Inky inky;
|
||||
ghostFrightenHelper(inky);
|
||||
ghostFrightenTest(inky);
|
||||
|
||||
pacman::Pinky pinky;
|
||||
ghostFrightenHelper(pinky);
|
||||
ghostFrightenTest(pinky);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void ghostDeadHelper(T & ghost) {
|
||||
static void ghostDeadTest(T & ghost) {
|
||||
REQUIRE_FALSE(ghost.isEyes());
|
||||
ghost.die();
|
||||
REQUIRE(ghost.isEyes());
|
||||
|
@ -65,14 +64,14 @@ static void ghostDeadHelper(T & ghost) {
|
|||
|
||||
TEST_CASE("Ghosts can die", "[ghosts]") {
|
||||
pacman::Blinky blinky;
|
||||
ghostDeadHelper(blinky);
|
||||
ghostDeadTest(blinky);
|
||||
|
||||
pacman::Clyde clyde;
|
||||
ghostDeadHelper(clyde);
|
||||
ghostDeadTest(clyde);
|
||||
|
||||
pacman::Inky inky;
|
||||
ghostDeadHelper(inky);
|
||||
ghostDeadTest(inky);
|
||||
|
||||
pacman::Pinky pinky;
|
||||
ghostDeadHelper(pinky);
|
||||
ghostDeadTest(pinky);
|
||||
}
|
||||
|
|
45
test/testPellets.cpp
Normal file
45
test/testPellets.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "Pellets.hpp"
|
||||
#include "SuperPellets.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
template<typename T>
|
||||
static void pelletInitTest(const T & pellets, size_t size, size_t spriteX, size_t spriteY) {
|
||||
REQUIRE(pellets.currentPositions().size() == size);
|
||||
REQUIRE(pellets.currentSprite().x == spriteX);
|
||||
REQUIRE(pellets.currentSprite().y == spriteY);
|
||||
}
|
||||
|
||||
TEST_CASE("Pellet initialization", "[pellets]") {
|
||||
pacman::Pellets pellets;
|
||||
pelletInitTest(pellets, 240, 1, 9);
|
||||
|
||||
pacman::SuperPellets superPellets;
|
||||
pelletInitTest(superPellets, 4, 0, 9);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void pelletEatingTest(T & pellets, size_t countBefore, size_t countAfter, size_t x, size_t y) {
|
||||
REQUIRE(pellets.currentPositions().size() == countBefore);
|
||||
if (countBefore != countAfter) {
|
||||
REQUIRE(pellets.eatPelletAtPosition(pacman::GridPosition{ x, y }));
|
||||
} else {
|
||||
REQUIRE_FALSE(pellets.eatPelletAtPosition(pacman::GridPosition{ x, y }));
|
||||
}
|
||||
REQUIRE(pellets.currentPositions().size() == countAfter);
|
||||
}
|
||||
|
||||
TEST_CASE("Eating pellets", "[pellets]") {
|
||||
pacman::Pellets pellets;
|
||||
pelletEatingTest(pellets, 240, 240, 0, 0); // wall
|
||||
pelletEatingTest(pellets, 240, 239, 1, 1); // pellet
|
||||
pelletEatingTest(pellets, 239, 239, 1, 1);
|
||||
pelletEatingTest(pellets, 239, 238, 1, 2); // pellet
|
||||
pelletEatingTest(pellets, 238, 238, 1, 2);
|
||||
pelletEatingTest(pellets, 238, 238, 1, 3); // super pellet
|
||||
|
||||
pacman::SuperPellets superPellets;
|
||||
pelletEatingTest(superPellets, 4, 4, 0, 0); // wall
|
||||
pelletEatingTest(superPellets, 4, 3, 1, 3); // super pellet
|
||||
pelletEatingTest(superPellets, 3, 3, 1, 3);
|
||||
pelletEatingTest(superPellets, 3, 3, 2, 1); // pellet
|
||||
}
|
Loading…
Reference in a new issue