diff options
| author | Charlie Blake | 2018-06-08 14:21:53 +0100 |
|---|---|---|
| committer | Charlie Blake | 2018-06-08 14:22:04 +0100 |
| commit | 04cbac28b7d62828dfa43cd77ed8dc790f24237c (patch) | |
| tree | 8cb34b002b4de591452c632938c16208117c0115 /src/test/test_helper.cpp | |
| parent | Move auto found. logic into sep. file (diff) | |
| download | metasol-04cbac28b7d62828dfa43cd77ed8dc790f24237c.tar.gz metasol-04cbac28b7d62828dfa43cd77ed8dc790f24237c.zip | |
Fix built move bug and add unit tests
Diffstat (limited to 'src/test/test_helper.cpp')
| -rw-r--r-- | src/test/test_helper.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 6f2a68d..18b36eb 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -14,7 +14,9 @@ #define ASSERT_(t_f, statement) ASSERT_TRUE((statement) == (t_f)) using namespace rapidjson; -using namespace std; +using std::initializer_list; +using std::vector; +using std::ostream; bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) { const Document in_doc = json_helper::get_file_json(input_file); @@ -57,3 +59,39 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, } ASSERT_TRUE(n->children.empty()); } + +void test_helper::run_built_group_test(sol_rules sr, + initializer_list<pile> piles, + vector<move> exp_moves) { + game_state gs(sr, piles); + vector<move> actual_moves = gs.get_legal_moves(); + + ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +bool test_helper::moves_eq(vector<move>& exp_moves, vector<move>& actual_moves) { + if (exp_moves.size() != actual_moves.size()) return false; + + for (move m : actual_moves) { + auto it = find(begin(exp_moves), end(exp_moves), m); + bool found = it != end(exp_moves); + + if (found) exp_moves.erase(it); + else return false; + } + + return true; +} +ostream& operator <<(ostream& os, const move& m) { + return os << "move:(" << int(m.from) + << "," << int(m.to) + << "," << int(m.count) + << ")"; +} + +ostream& operator <<(ostream& os, const vector<move>& moves) { + for (const move m : moves) { + os << m << ",\n"; + } + return os; +} |
