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

75 lines
1.6 KiB

#include <catch2/catch_test_macros.hpp>
#include "../game_engine.hpp"
#include <fmt/core.h>
using namespace fmt;
TEST_CASE("basic brainfuck test", "[brainfuck]") {
Brainfucker bf;
string code{"+.>+.>+.>"};
bf.set_code(code);
bf.run(code.size());
REQUIRE(bf.data[0] == 1);
REQUIRE(bf.data[1] == 1);
REQUIRE(bf.data[2] == 1);
bf.reset();
REQUIRE(bf.data[0] == 0);
REQUIRE(bf.data[1] == 0);
REQUIRE(bf.data[2] == 0);
REQUIRE(bf.code.empty());
}
TEST_CASE("brainfuck loop test", "[brainfuck]") {
Brainfucker bf;
const string expected{"Hello World!\n"};
// this is a hello world program from wikipedia
// but at the end I rewind dp so I can analyze it
string code{"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."};
bf.set_code(code);
// have it run a bunch of times
bf.run(10000);
string output = bf.to_string();
REQUIRE(output == expected);
}
TEST_CASE("game engine can start and take hit", "[game_engine]") {
// test fails on purpose right now
GameEngine game{4};
string err{"error"};
game.start_round();
game.hit(err);
game.end_round();
REQUIRE(game.is_dead() == true);
}
TEST_CASE("", "[game_engine]") {
// test fails on purpose right now
GameEngine game{100};
string err{"error"};
game.start_round();
game.hit(err);
game.end_round();
REQUIRE(game.hit_points < 100);
REQUIRE(game.rounds == 1);
REQUIRE(game.streak == 0);
REQUIRE(game.is_dead() == false);
game.start_round();
game.end_round();
REQUIRE(game.hit_points == 100);
REQUIRE(game.rounds == 2);
REQUIRE(game.streak == 1);
REQUIRE(game.is_dead() == false);
}