add unit tests

This commit is contained in:
Maximilian Keßler 2023-11-17 09:28:04 +01:00
parent 8cc30eb270
commit c478258334
Signed by: max
GPG Key ID: BCC5A619923C0BA5
1 changed files with 49 additions and 0 deletions

49
test/unit_test.cpp Normal file
View File

@ -0,0 +1,49 @@
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/json.hpp>
#include "game_state.h"
#include "parse_game.h"
using namespace Hanabi;
std::string const game_json_str = R"({"id":1058099,"players":["NoVarkusKahlsen","RamaNoVarjan","PurpleJoeVar"],"deck":[{"suitIndex":3,"rank":5},{"suitIndex":2,"rank":2},{"suitIndex":4,"rank":5},{"suitIndex":3,"rank":1},{"suitIndex":1,"rank":3},{"suitIndex":2,"rank":1},{"suitIndex":1,"rank":2},{"suitIndex":4,"rank":2},{"suitIndex":2,"rank":3},{"suitIndex":2,"rank":5},{"suitIndex":4,"rank":1},{"suitIndex":3,"rank":1},{"suitIndex":0,"rank":3},{"suitIndex":4,"rank":1},{"suitIndex":3,"rank":4},{"suitIndex":4,"rank":1},{"suitIndex":0,"rank":4},{"suitIndex":4,"rank":4},{"suitIndex":3,"rank":1},{"suitIndex":0,"rank":3},{"suitIndex":0,"rank":1},{"suitIndex":2,"rank":1},{"suitIndex":2,"rank":1},{"suitIndex":3,"rank":3},{"suitIndex":1,"rank":1},{"suitIndex":3,"rank":2},{"suitIndex":1,"rank":4},{"suitIndex":1,"rank":4},{"suitIndex":3,"rank":2},{"suitIndex":0,"rank":4},{"suitIndex":0,"rank":2},{"suitIndex":0,"rank":1},{"suitIndex":0,"rank":2},{"suitIndex":4,"rank":2},{"suitIndex":2,"rank":4},{"suitIndex":1,"rank":1},{"suitIndex":1,"rank":3},{"suitIndex":3,"rank":4},{"suitIndex":2,"rank":2},{"suitIndex":4,"rank":4},{"suitIndex":2,"rank":4},{"suitIndex":2,"rank":3},{"suitIndex":1,"rank":2},{"suitIndex":1,"rank":1},{"suitIndex":0,"rank":5},{"suitIndex":1,"rank":5},{"suitIndex":0,"rank":1},{"suitIndex":3,"rank":3},{"suitIndex":4,"rank":3},{"suitIndex":4,"rank":3}],"actions":[{"type":2,"target":1,"value":2},{"type":0,"target":5,"value":0},{"type":2,"target":0,"value":2},{"type":2,"target":2,"value":0},{"type":0,"target":15,"value":0},{"type":3,"target":1,"value":2},{"type":2,"target":1,"value":4},{"type":3,"target":0,"value":5},{"type":1,"target":10,"value":0},{"type":0,"target":1,"value":0},{"type":2,"target":2,"value":3},{"type":3,"target":1,"value":3},{"type":1,"target":3,"value":0},{"type":0,"target":7,"value":0},{"type":2,"target":0,"value":3},{"type":3,"target":2,"value":4},{"type":0,"target":20,"value":0},{"type":1,"target":11,"value":0},{"type":0,"target":18,"value":0},{"type":3,"target":2,"value":1},{"type":1,"target":13,"value":0},{"type":0,"target":23,"value":0},{"type":2,"target":2,"value":3},{"type":0,"target":24,"value":0},{"type":0,"target":25,"value":0},{"type":0,"target":8,"value":0},{"type":1,"target":22,"value":0},{"type":0,"target":27,"value":0},{"type":1,"target":21,"value":0},{"type":2,"target":0,"value":0},{"type":0,"target":30,"value":0},{"type":0,"target":6,"value":0},{"type":3,"target":0,"value":3},{"type":0,"target":4,"value":0},{"type":1,"target":28,"value":0},{"type":3,"target":1,"value":5},{"type":0,"target":34,"value":0},{"type":0,"target":9,"value":0},{"type":0,"target":12,"value":0},{"type":2,"target":2,"value":1},{"type":1,"target":31,"value":0},{"type":0,"target":26,"value":0},{"type":1,"target":19,"value":0},{"type":1,"target":33,"value":0},{"type":2,"target":1,"value":0},{"type":1,"target":32,"value":0},{"type":0,"target":16,"value":0},{"type":2,"target":1,"value":0},{"type":3,"target":1,"value":5},{"type":0,"target":44,"value":0},{"type":3,"target":1,"value":5},{"type":1,"target":36,"value":0},{"type":0,"target":45,"value":0},{"type":3,"target":1,"value":3},{"type":3,"target":1,"value":3},{"type":0,"target":47,"value":0},{"type":0,"target":14,"value":0},{"type":0,"target":0,"value":0},{"type":0,"target":48,"value":0},{"type":0,"target":17,"value":0}],"seed":"p3v0s23"})";
boost::json::value const game_json = boost::json::parse(game_json_str);
BOOST_AUTO_TEST_SUITE(parsing)
BOOST_AUTO_TEST_CASE(parse_deck)
{
BOOST_CHECK_NO_THROW(auto deck = Parsing::parse_deck(game_json.at("deck")));
auto const [deck, num_suits] = Parsing::parse_deck(game_json.at("deck"));
BOOST_CHECK_EQUAL(num_suits, 5);
BOOST_REQUIRE_EQUAL(deck.size(), 50);
BOOST_CHECK_EQUAL(deck[0], Cards::b5);
BOOST_CHECK_EQUAL(deck[1], Cards::g2);
BOOST_CHECK_EQUAL(deck[2], Cards::p5);
BOOST_CHECK_EQUAL(deck[3], Cards::b1);
BOOST_CHECK_EQUAL(deck[4], Cards::y3);
BOOST_CHECK_EQUAL(deck[5], Cards::g1);
BOOST_CHECK_EQUAL(deck[6], Cards::y2);
BOOST_CHECK_EQUAL(deck[7], Cards::p2);
BOOST_CHECK_EQUAL(deck[8], Cards::g3);
BOOST_CHECK_EQUAL(deck[9], Cards::g5);
BOOST_CHECK_EQUAL(deck[10], Cards::p1);
BOOST_CHECK_EQUAL(deck[11], Cards::b1);
BOOST_CHECK_EQUAL(deck[12], Cards::r3);
BOOST_CHECK_EQUAL(deck[13], Cards::p1);
BOOST_CHECK_EQUAL(deck[14], Cards::b4);
}
BOOST_AUTO_TEST_CASE(parse_actions)
{
BOOST_CHECK_NO_THROW(auto actions = Parsing::parse_actions(game_json.at("actions")));
std::vector<Parsing::HanabLiveAction> actions = Parsing::parse_actions(game_json.at("actions"));
BOOST_CHECK_EQUAL(actions[0].type, ActionType::color_clue);
}
BOOST_AUTO_TEST_CASE(parse_game)
{
BOOST_CHECK_NO_THROW(auto game = Parsing::parse_game(game_json.as_object()));
}
BOOST_AUTO_TEST_SUITE_END()