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

master
Zed A. Shaw 2 months ago
parent 07a212d9d7
commit 07553400f5
  1. 4
      Makefile
  2. 2
      builder.cpp
  3. 11
      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: config:
powershell "cp tarpit_sample.json .tarpit.json" powershell "cp tarpit_sample.json .tarpit.json"
test: test: build
meson test -C builddir --suite turings_tarpit ./builddir/runtests
# make an install for real maybe copy dll and .exe to dir and zip? # make an install for real maybe copy dll and .exe to dir and zip?
install: build test install: build test

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

@ -25,10 +25,8 @@ int GameEngine::determine_damage(string &type) {
} }
void GameEngine::reset() { void GameEngine::reset() {
rounds = 0;
streak = 0; streak = 0;
hit_points = starting_hp; hit_points = starting_hp;
hits_taken = 0;
} }
bool GameEngine::hit(string &type) { bool GameEngine::hit(string &type) {
@ -83,8 +81,15 @@ void GameEngine::in_round(GameEvent ev, string &hit_type) {
} }
void GameEngine::dead(GameEvent ev) { void GameEngine::dead(GameEvent ev) {
if(ev == GameEvent::BUILD_DONE) {
reset(); reset();
state(GameState::IDLE); state(GameState::FAILURE);
failure(ev);
} else if(ev == GameEvent::HIT) {
++hits_taken;
} else {
state(GameState::DEAD);
}
} }
void GameEngine::success(GameEvent ev) { 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) { void event(GameEvent ev) {
switch(_state) { switch(_state) {
FSM_STATE(GameState::START, start, ev); FSM_STATE_LOG(GameState, START, start, ev);
FSM_STATE(GameState::IDLE, idle, ev); FSM_STATE_LOG(GameState, IDLE, idle, ev);
FSM_STATE(GameState::DEAD, dead, ev); FSM_STATE_LOG(GameState, DEAD, dead, ev);
FSM_STATE(GameState::SUCCESS, success, ev); FSM_STATE_LOG(GameState, SUCCESS, success, ev);
FSM_STATE(GameState::FAILURE, failure, ev); FSM_STATE_LOG(GameState, FAILURE, failure, ev);
case GameState::IN_ROUND: { case GameState::IN_ROUND: {
string hit_type = ""; string hit_type = "";
in_round(ev, 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 start(GameEvent ev);
void idle(GameEvent ev); void idle(GameEvent ev);
void in_round(GameEvent ev, string &hit_type); void in_round(GameEvent ev, string &hit_type);
@ -75,7 +79,6 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
void success(GameEvent ev); void success(GameEvent ev);
void failure(GameEvent ev); void failure(GameEvent ev);
// current API that will die
void heal(); void heal();
bool hit(string &type); bool hit(string &type);
void reset(); void reset();

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

@ -4,13 +4,38 @@
using namespace fmt; 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 // test fails on purpose right now
GameEngine game{4}; 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 // test fails on purpose right now
GameEngine game{100}; GameEngine game{100};
REQUIRE(game.is_dead() == false); REQUIRE(game.is_dead() == false);

Loading…
Cancel
Save