From 819a1064c5142a9b2f04ff8149d34fc915c18322 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Fri, 8 Jun 2018 10:31:22 +0100 Subject: Refactor legal moves gen and moves logic --- src/test/test_helper.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/test/test_helper.cpp') diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 9d928c6..6f2a68d 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -5,7 +5,7 @@ #include #include "test_helper.h" -#include "../main/game/game_state.h" +#include "../main/game/search-state/game_state.h" #include "../main/solver/solver.h" #include "../main/input-output/input/json-parsing/json_helper.h" #include "../main/input-output/input/json-parsing/rules_parser.h" @@ -50,10 +50,10 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, solver::node const *n = &sol.get_search_tree(); for (card c : cards) { n = &n->children.back(); - ASSERT_TRUE(n->move.is_dominance()); - ASSERT_TRUE(gs.get_data()[n->move.from].top_card() == c); - ASSERT_TRUE(n->move.to >= 0 && n->move.to <= 4); - gs.make_move(n->move); + ASSERT_TRUE(n->mv.is_dominance()); + ASSERT_TRUE(gs.get_data()[n->mv.from].top_card() == c); + ASSERT_TRUE(n->mv.to >= 0 && n->mv.to <= 4); + gs.make_move(n->mv); } ASSERT_TRUE(n->children.empty()); } -- cgit v1.2.1 From 04cbac28b7d62828dfa43cd77ed8dc790f24237c Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Fri, 8 Jun 2018 14:21:53 +0100 Subject: Fix built move bug and add unit tests --- src/test/test_helper.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/test/test_helper.cpp') 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 piles, + vector exp_moves) { + game_state gs(sr, piles); + vector actual_moves = gs.get_legal_moves(); + + ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +bool test_helper::moves_eq(vector& exp_moves, vector& 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& moves) { + for (const move m : moves) { + os << m << ",\n"; + } + return os; +} -- cgit v1.2.1 From a7396c5497601855fad019cfd145ca6c93e1c40f Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Fri, 8 Jun 2018 21:54:48 +0100 Subject: Refactor moves logic --- src/test/test_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/test_helper.cpp') diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 18b36eb..dbc6f0d 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -52,7 +52,7 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, solver::node const *n = &sol.get_search_tree(); for (card c : cards) { n = &n->children.back(); - ASSERT_TRUE(n->mv.is_dominance()); + ASSERT_TRUE(n->mv.type == move::mtype::dominance); ASSERT_TRUE(gs.get_data()[n->mv.from].top_card() == c); ASSERT_TRUE(n->mv.to >= 0 && n->mv.to <= 4); gs.make_move(n->mv); -- cgit v1.2.1