A weird game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
turings-tarpit/tests/game_engine.cpp

80 lines
2.3 KiB

#include <catch2/catch_test_macros.hpp>
#include "../game_engine.hpp"
#include <fmt/core.h>
using namespace fmt;
TEST_CASE("game engine death cycle", "[game_engine]") {
// test fails on purpose right now
GameEngine game{4};
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 can do success build", "[game_engine]") {
GameEngine game{10};
// test fails on purpose right now
for(int i = 0; i < 10; i++) {
game.event(GameEvent::BUILD_START);
game.event(GameEvent::BUILD_SUCCESS);
REQUIRE(game.hits_taken == 0);
REQUIRE(game.hit_points == game.starting_hp);
// confirm streaks, hit_taken, rounds are maintained
REQUIRE(game.streak == i);
REQUIRE(game.rounds == i);
REQUIRE(game.is_dead() == false);
game.event(GameEvent::BUILD_DONE);
}
// if you hit a streak of 10 then you get one of two bonuses
// 1. 10% more hp
// 2. 1 free death
game.add_bonus(GameBonus::MORE_HP);
REQUIRE(game.max_hp() > game.starting_hp);
REQUIRE(game.hit_points == game.starting_hp * game.hp_bonus);
REQUIRE(game.hit_points == game.max_hp());
game.add_bonus(GameBonus::FREE_DEATH);
REQUIRE(game.free_death == true);
game.event(GameEvent::BUILD_START);
game.event(GameEvent::HIT, "error");
game.event(GameEvent::HIT, "error");
game.event(GameEvent::HIT, "error");
REQUIRE(game.is_dead() == false);
REQUIRE(game.streak == 10);
game.event(GameEvent::BUILD_FAILED);
game.event(GameEvent::BUILD_DONE);
REQUIRE(game.streak == 10);
REQUIRE(game.free_death == false);
REQUIRE(game.hit_points == int(game.max_hp() * 0.5f));
}