Test suite now accurately runs the GameEngine FSM for multiple rounds.

master
Zed A. Shaw 3 months ago
parent 07a212d9d7
commit 07553400f5
  1. 4
      Makefile
  2. 2
      builder.cpp
  3. 13
      game_engine.cpp
  4. 17
      game_engine.hpp
  5. 1
      status.txt
  6. 31
      tests/game_engine.cpp

@ -12,8 +12,8 @@ build: patch
config:
powershell "cp tarpit_sample.json .tarpit.json"
test:
meson test -C builddir --suite turings_tarpit
test: build
./builddir/runtests
# make an install for real maybe copy dll and .exe to dir and zip?
install: build test

@ -83,7 +83,7 @@ void Builder::building(BuildEvent ev) {
gui.build_works();
} else {
game.event(GameEvent::BUILD_FAILED);
gui.build_failed(true, build_cmd);
gui.build_failed(!game.is_dead(), build_cmd);
}
build_out = NULL;

@ -25,10 +25,8 @@ int GameEngine::determine_damage(string &type) {
}
void GameEngine::reset() {
rounds = 0;
streak = 0;
hit_points = starting_hp;
hits_taken = 0;
}
bool GameEngine::hit(string &type) {
@ -83,8 +81,15 @@ void GameEngine::in_round(GameEvent ev, string &hit_type) {
}
void GameEngine::dead(GameEvent ev) {
reset();
state(GameState::IDLE);
if(ev == GameEvent::BUILD_DONE) {
reset();
state(GameState::FAILURE);
failure(ev);
} else if(ev == GameEvent::HIT) {
++hits_taken;
} else {
state(GameState::DEAD);
}
}
void GameEngine::success(GameEvent ev) {

@ -52,13 +52,18 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
}
}
void event(GameEvent ev, const char *hit_type) {
string ht{hit_type};
event(ev, ht);
}
void event(GameEvent ev) {
switch(_state) {
FSM_STATE(GameState::START, start, ev);
FSM_STATE(GameState::IDLE, idle, ev);
FSM_STATE(GameState::DEAD, dead, ev);
FSM_STATE(GameState::SUCCESS, success, ev);
FSM_STATE(GameState::FAILURE, failure, ev);
FSM_STATE_LOG(GameState, START, start, ev);
FSM_STATE_LOG(GameState, IDLE, idle, ev);
FSM_STATE_LOG(GameState, DEAD, dead, ev);
FSM_STATE_LOG(GameState, SUCCESS, success, ev);
FSM_STATE_LOG(GameState, FAILURE, failure, ev);
case GameState::IN_ROUND: {
string hit_type = "";
in_round(ev, hit_type);
@ -67,7 +72,6 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
}
}
// FSM to replace the others
void start(GameEvent ev);
void idle(GameEvent ev);
void in_round(GameEvent ev, string &hit_type);
@ -75,7 +79,6 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
void success(GameEvent ev);
void failure(GameEvent ev);
// current API that will die
void heal();
bool hit(string &type);
void reset();

@ -4,7 +4,6 @@
BUGS:
* BUG: Log doesn't scroll.
* BUG: plays two sounds on death.
TODO:
* Rewrite dbc.hpp to actually work.

@ -4,13 +4,38 @@
using namespace fmt;
TEST_CASE("game engine can start and take hit", "[game_engine]") {
TEST_CASE("game engine death cycle", "[game_engine]") {
// test fails on purpose right now
GameEngine game{4};
REQUIRE(!game.is_dead() == true);
for(int i = 0; i < 4; i++) {
game.event(GameEvent::BUILD_START);
REQUIRE(game.hit_points == 4);
// confirm streaks, hit_taken, rounds are maintained
REQUIRE(game.streak == 0);
REQUIRE(game.rounds == i);
game.event(GameEvent::HIT, "error");
REQUIRE(game.hit_points == 0);
// in dead state these are ignored
game.event(GameEvent::HIT);
game.event(GameEvent::HIT);
game.event(GameEvent::HIT);
game.event(GameEvent::HIT);
REQUIRE(game.hit_points == 0);
REQUIRE(game.is_dead() == true);
// this is ignored too for now
game.event(GameEvent::BUILD_FAILED);
REQUIRE(game.hits_taken == 5);
REQUIRE(game.hit_points == 0);
REQUIRE(game.is_dead() == true);
game.event(GameEvent::BUILD_DONE);
}
}
TEST_CASE("", "[game_engine]") {
TEST_CASE("game can do success build", "[game_engine]") {
// test fails on purpose right now
GameEngine game{100};
REQUIRE(game.is_dead() == false);

Loading…
Cancel
Save