Adding simple deterministic fuzz test for GameState.

This commit is contained in:
Ólafur Waage 2021-09-09 11:15:31 +02:00
parent 2f62f7ae1d
commit 1ad8a1ec8e
2 changed files with 26 additions and 2 deletions

View file

@ -1,2 +0,0 @@
#include "PacMan.hpp"
#include <gtest/gtest.h>

26
test/testGameState.cpp Normal file
View file

@ -0,0 +1,26 @@
#include "GameState.hpp"
#include <gtest/gtest.h>
#include <fmt/format.h>
TEST(GameStateTest, Fuzz) {
pacman::GameState gameState;
//fmt::print("{}\n", gameState.pellets.currentPositions().size());
int pacManDeathCount = 0;
bool canCountDeath = false;
for (std::size_t i = 0; i < 50000; ++i) {
gameState.inputState.up = i % 7 ? true : false;
gameState.inputState.down = i % 11 ? true : false;
gameState.inputState.left = i % 13 ? true : false;
gameState.inputState.right = i % 17 ? true : false;
canCountDeath = !gameState.isPacManDying();
gameState.step(std::chrono::milliseconds(1000 / 30));
if (canCountDeath && gameState.isPacManDying()) {
pacManDeathCount++;
}
}
//fmt::print("{}\n", pacManDeathCount);
//fmt::print("{}\n", gameState.pellets.currentPositions().size());
}