From 1ad8a1ec8e52fcd519fbfbcfc45a481bf250546c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20Waage?= Date: Thu, 9 Sep 2021 11:15:31 +0200 Subject: [PATCH] Adding simple deterministic fuzz test for GameState. --- test/testGame.cpp | 2 -- test/testGameState.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) delete mode 100644 test/testGame.cpp create mode 100644 test/testGameState.cpp diff --git a/test/testGame.cpp b/test/testGame.cpp deleted file mode 100644 index 74c51ca..0000000 --- a/test/testGame.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "PacMan.hpp" -#include diff --git a/test/testGameState.cpp b/test/testGameState.cpp new file mode 100644 index 0000000..618c0e6 --- /dev/null +++ b/test/testGameState.cpp @@ -0,0 +1,26 @@ +#include "GameState.hpp" +#include +#include + +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()); +} \ No newline at end of file