Use an ostringstream for the output and make the test actually confirm the results.
This commit is contained in:
parent
38104f60f3
commit
4227ee1cdc
3 changed files with 13 additions and 4 deletions
|
@ -121,7 +121,7 @@ void Brainfucker::run(int ticks) {
|
||||||
data[dp] = data[dp] - 1;
|
data[dp] = data[dp] - 1;
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
cout << (char)data.at(dp);
|
out << (char)data.at(dp);
|
||||||
break;
|
break;
|
||||||
case ',':
|
case ',':
|
||||||
print(ERROR, "Not implemented.\n");
|
print(ERROR, "Not implemented.\n");
|
||||||
|
@ -162,7 +162,6 @@ void Brainfucker::reset() {
|
||||||
data.fill(0);
|
data.fill(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GameEngine::GameEngine(int hp) : hit_points(hp) {};
|
GameEngine::GameEngine(int hp) : hit_points(hp) {};
|
||||||
|
|
||||||
int GameEngine::determine_damage(string &type) {
|
int GameEngine::determine_damage(string &type) {
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Brainfucker {
|
class Brainfucker {
|
||||||
size_t dp = 0;
|
|
||||||
size_t ip = 0;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
size_t dp = 0;
|
||||||
|
size_t ip = 0;
|
||||||
|
ostringstream out;
|
||||||
array<int, 100> data = {};
|
array<int, 100> data = {};
|
||||||
string code = {};
|
string code = {};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include "../game_engine.hpp"
|
#include "../game_engine.hpp"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
using namespace fmt;
|
||||||
|
|
||||||
TEST_CASE("basic brainfuck test", "[brainfuck]") {
|
TEST_CASE("basic brainfuck test", "[brainfuck]") {
|
||||||
Brainfucker bf;
|
Brainfucker bf;
|
||||||
|
@ -26,11 +29,16 @@ TEST_CASE("basic brainfuck test", "[brainfuck]") {
|
||||||
|
|
||||||
TEST_CASE("brainfuck loop test", "[brainfuck]") {
|
TEST_CASE("brainfuck loop test", "[brainfuck]") {
|
||||||
Brainfucker bf;
|
Brainfucker bf;
|
||||||
|
const string expected{"Hello World!\n"};
|
||||||
// this is a hello world program from wikipedia
|
// this is a hello world program from wikipedia
|
||||||
|
// but at the end I rewind dp so I can analyze it
|
||||||
string code{"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."};
|
string code{"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."};
|
||||||
|
|
||||||
bf.set_code(code);
|
bf.set_code(code);
|
||||||
bf.run(code.size());
|
bf.run(code.size());
|
||||||
|
|
||||||
|
string output = bf.out.str();
|
||||||
|
REQUIRE(output == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("game engine can start and take hit", "[brainfuck]") {
|
TEST_CASE("game engine can start and take hit", "[brainfuck]") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue