aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/resources/alpha_star/ComplexSolvable.json6
-rw-r--r--src/test/resources/alpha_star/ComplexUnsolvable.json6
-rw-r--r--src/test/resources/alpha_star/SimpleSolvable.json6
-rw-r--r--src/test/resources/alpha_star/SimpleUnsolvable.json6
-rw-r--r--src/test/test_helper.cpp50
-rw-r--r--src/test/test_helper.h9
-rw-r--r--src/test/unit_tests/built_group_move_gen_test.cpp254
-rw-r--r--src/test/unit_tests/foundations_dominance_test.cpp2
-rw-r--r--src/test/unit_tests/global_cache_test.cpp2
-rw-r--r--src/test/unit_tests/legal_move_gen_test.cpp170
10 files changed, 388 insertions, 123 deletions
diff --git a/src/test/resources/alpha_star/ComplexSolvable.json b/src/test/resources/alpha_star/ComplexSolvable.json
index e7eedd5..ab6b24e 100644
--- a/src/test/resources/alpha_star/ComplexSolvable.json
+++ b/src/test/resources/alpha_star/ComplexSolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["3S","2C","3C","5C","5H","4H"],
- ["4S","4C","5S","2D","5D"],
- ["2S","2H","3H","4D","3D"]
+ ["6C","3S","2C","3C","5C","5H","4H"],
+ ["6S","4S","4C","5S","2D","5D"],
+ ["6H","6D","2S","2H","3H","4D","3D"]
]
} \ No newline at end of file
diff --git a/src/test/resources/alpha_star/ComplexUnsolvable.json b/src/test/resources/alpha_star/ComplexUnsolvable.json
index a01f2b5..56ea441 100644
--- a/src/test/resources/alpha_star/ComplexUnsolvable.json
+++ b/src/test/resources/alpha_star/ComplexUnsolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["2S","2C","3C","5C","5H","4H"],
- ["4S","4C","5S","2D","5D"],
- ["3S","2H","3H","4D","3D"]
+ ["6C","2S","2C","3C","5C","5H","4H"],
+ ["6S","4S","4C","5S","2D","5D"],
+ ["6H","6D","3S","2H","3H","4D","3D"]
]
}
diff --git a/src/test/resources/alpha_star/SimpleSolvable.json b/src/test/resources/alpha_star/SimpleSolvable.json
index d160e42..7994021 100644
--- a/src/test/resources/alpha_star/SimpleSolvable.json
+++ b/src/test/resources/alpha_star/SimpleSolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["5S","5C","4C","3C","2S","2C"],
- ["5D","4D","3S","3D","2D"],
- ["5H","4S","4H","3H","2H"]
+ ["6C","5S","5C","4C","3C","2S","2C"],
+ ["6S","6D","5D","4D","3S","3D","2D"],
+ ["6H","5H","4S","4H","3H","2H"]
]
}
diff --git a/src/test/resources/alpha_star/SimpleUnsolvable.json b/src/test/resources/alpha_star/SimpleUnsolvable.json
index 1097473..ac6741e 100644
--- a/src/test/resources/alpha_star/SimpleUnsolvable.json
+++ b/src/test/resources/alpha_star/SimpleUnsolvable.json
@@ -1,7 +1,7 @@
{
"tableau piles": [
- ["2S","2C","3C","4C","5S","5C"],
- ["2D","3D","4S","4D","5D"],
- ["2H","3S","3H","4H","5H"]
+ ["2S","2C","3C","4C","5S","5C","6C"],
+ ["2D","3D","4S","4D","5D","6S","6D"],
+ ["2H","3S","3H","4H","5H","6H"]
]
} \ No newline at end of file
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index 9d928c6..dbc6f0d 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -5,7 +5,7 @@
#include <gtest/gtest.h>
#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"
@@ -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);
@@ -50,10 +52,46 @@ 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.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);
}
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;
+}
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
index b0199af..463a935 100644
--- a/src/test/test_helper.h
+++ b/src/test/test_helper.h
@@ -9,15 +9,20 @@
#include "../main/game/sol_rules.h"
#include "../main/game/card.h"
+#include "../main/game/pile.h"
+#include "../main/game/move.h"
class test_helper {
public:
static bool is_solvable(const std::string&, const std::string&);
- static void run_card_cache_test(sol_rules::build_policy, bool, bool);
-
static void run_foundations_dominance_test(sol_rules::build_policy policy,
std::vector<card> cards);
+ static void run_built_group_test(sol_rules sr, std::initializer_list<pile>, std::vector<move>);
+ static bool moves_eq(std::vector<move>&, std::vector<move>&);
};
+std::ostream& operator <<(std::ostream&, const move&);
+std::ostream& operator <<(std::ostream&, const std::vector<move>&);
+
#endif //SOLVITAIRE_TEST_HELPER_H
diff --git a/src/test/unit_tests/built_group_move_gen_test.cpp b/src/test/unit_tests/built_group_move_gen_test.cpp
new file mode 100644
index 0000000..34e2b07
--- /dev/null
+++ b/src/test/unit_tests/built_group_move_gen_test.cpp
@@ -0,0 +1,254 @@
+//
+// Created by thecharlesblake on 1/11/18.
+//
+
+#include <gtest/gtest.h>
+
+#include "../test_helper.h"
+#include "../../main/game/search-state/game_state.h"
+#include "../../main/game/sol_rules.h"
+
+typedef sol_rules::build_policy pol;
+
+using std::vector;
+using std::ostream;
+using std::initializer_list;
+
+TEST(BuiltGroupMoveGen, SameSuitEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::SAME_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 0, 1),
+ move(move::mtype::regular, 2, 0, 1),
+ move(move::mtype::regular, 3, 0, 1),
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 1, 0, 2),
+ move(move::mtype::built_group, 1, 0, 3),
+ move(move::mtype::built_group, 1, 4, 2),
+ move(move::mtype::built_group, 1, 4, 3)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, RedBlackEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::RED_BLACK;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 0, 1),
+ move(move::mtype::regular, 2, 0, 1),
+ move(move::mtype::regular, 3, 0, 1),
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 2, 0, 2),
+ move(move::mtype::built_group, 2, 0, 3),
+ move(move::mtype::built_group, 2, 4, 2),
+ move(move::mtype::built_group, 2, 4, 3),
+
+ move(move::mtype::built_group, 3, 0, 2),
+ move(move::mtype::built_group, 3, 4, 2)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, AnySuitEmpty) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 0, 1),
+ move(move::mtype::regular, 2, 0, 1),
+ move(move::mtype::regular, 3, 0, 1),
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 1, 0, 2),
+ move(move::mtype::built_group, 1, 0, 3),
+ move(move::mtype::built_group, 1, 4, 2),
+ move(move::mtype::built_group, 1, 4, 3),
+
+ move(move::mtype::built_group, 2, 0, 2),
+ move(move::mtype::built_group, 2, 0, 3),
+ move(move::mtype::built_group, 2, 4, 2),
+ move(move::mtype::built_group, 2, 4, 3),
+
+ move(move::mtype::built_group, 3, 0, 2),
+ move(move::mtype::built_group, 3, 0, 3),
+ move(move::mtype::built_group, 3, 4, 2),
+ move(move::mtype::built_group, 3, 4, 3),
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, CantMove) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = false;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 0, 1),
+ move(move::mtype::regular, 2, 0, 1),
+ move(move::mtype::regular, 3, 0, 1),
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, SameSuitOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::SAME_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+ move(move::mtype::regular, 0, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 1, 0, 3),
+ move(move::mtype::built_group, 1, 4, 2),
+ move(move::mtype::built_group, 1, 4, 3)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, RedBlackOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::RED_BLACK;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+ move(move::mtype::regular, 0, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 2, 0, 3),
+ move(move::mtype::built_group, 2, 4, 2),
+ move(move::mtype::built_group, 2, 4, 3),
+ move(move::mtype::built_group, 3, 4, 2)
+ }
+ );
+}
+
+TEST(BuiltGroupMoveGen, AnySuitOccupied) {
+ sol_rules sr;
+ sr.tableau_pile_count = 5;
+ sr.built_group_pol = pol::ANY_SUIT;
+ sr.move_built_group = true;
+
+ test_helper::run_built_group_test(
+ sr,
+ {
+ {"4C"},
+ {"3C","2C","AC"}, // Same suit
+ {"3H","2S","AH"}, // Red black
+ {"3D","2D","AS"}, // Any suit
+ {}
+ },
+ {
+ // Regular moves
+ move(move::mtype::regular, 1, 4, 1),
+ move(move::mtype::regular, 2, 4, 1),
+ move(move::mtype::regular, 3, 4, 1),
+ move(move::mtype::regular, 0, 4, 1),
+
+ // Built group moves
+ move(move::mtype::built_group, 1, 0, 3),
+ move(move::mtype::built_group, 2, 0, 3),
+ move(move::mtype::built_group, 3, 0, 3),
+
+ move(move::mtype::built_group, 1, 4, 2),
+ move(move::mtype::built_group, 1, 4, 3),
+
+ move(move::mtype::built_group, 2, 4, 2),
+ move(move::mtype::built_group, 2, 4, 3),
+
+ move(move::mtype::built_group, 3, 4, 2),
+ move(move::mtype::built_group, 3, 4, 3),
+ }
+ );
+}
diff --git a/src/test/unit_tests/foundations_dominance_test.cpp b/src/test/unit_tests/foundations_dominance_test.cpp
index 4a7d2aa..8fdc285 100644
--- a/src/test/unit_tests/foundations_dominance_test.cpp
+++ b/src/test/unit_tests/foundations_dominance_test.cpp
@@ -5,7 +5,7 @@
#include <gtest/gtest.h>
#include "../test_helper.h"
-#include "../../main/game/game_state.h"
+#include "../../main/game/search-state/game_state.h"
#include "../../main/game/global_cache.h"
typedef sol_rules::build_policy pol;
diff --git a/src/test/unit_tests/global_cache_test.cpp b/src/test/unit_tests/global_cache_test.cpp
index 97490ba..6b0accd 100644
--- a/src/test/unit_tests/global_cache_test.cpp
+++ b/src/test/unit_tests/global_cache_test.cpp
@@ -5,7 +5,7 @@
#include <gtest/gtest.h>
#include "../test_helper.h"
-#include "../../main/game/game_state.h"
+#include "../../main/game/search-state/game_state.h"
#include "../../main/game/global_cache.h"
typedef sol_rules::build_policy pol;
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index 4f4b7ef..f9ff52e 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -5,19 +5,17 @@
#include <gtest/gtest.h>
#include "../test_helper.h"
-#include "../../main/game/game_state.h"
+#include "../../main/game/search-state/game_state.h"
#include "../../main/game/sol_rules.h"
+#include "../../main/game/move.h"
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
typedef sol_rules::stock_deal_type sdt;
-typedef game_state::move mv;
-using namespace std;
-
-bool moves_eq(vector<mv>&, vector<mv>&);
-ostream& operator <<(ostream&, const mv&);
-ostream& operator <<(ostream&, const vector<mv>&);
+using std::vector;
+using std::ostream;
+using std::initializer_list;
TEST(LegalMoveGen, BuildPolAnySuit) {
sol_rules sr;
@@ -31,16 +29,16 @@ TEST(LegalMoveGen, BuildPolAnySuit) {
{"2S"},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4,0),
- mv(4,1),
- mv(4,2),
- mv(4,3)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 4,0),
+ move(move::mtype::regular, 4,1),
+ move(move::mtype::regular, 4,2),
+ move(move::mtype::regular, 4,3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolRedBlack) {
@@ -55,14 +53,14 @@ TEST(LegalMoveGen, BuildPolRedBlack) {
{"2D"},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4,1),
- mv(4,3)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 4,1),
+ move(move::mtype::regular, 4,3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolSameSuit) {
@@ -77,13 +75,13 @@ TEST(LegalMoveGen, BuildPolSameSuit) {
{"2D"},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4,0)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 4,0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, BuildPolNoBuild) {
@@ -98,12 +96,12 @@ TEST(LegalMoveGen, BuildPolNoBuild) {
{"2D"},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
+ vector<move> exp_moves = {
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolAny) {
@@ -115,13 +113,13 @@ TEST(LegalMoveGen, SpacesPolAny) {
{},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(1, 0)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 1, 0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolKings) {
@@ -134,13 +132,13 @@ TEST(LegalMoveGen, SpacesPolKings) {
{"AC"},
{"KD"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(2, 0)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 2, 0)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, SpacesPolNoBuild) {
@@ -152,12 +150,12 @@ TEST(LegalMoveGen, SpacesPolNoBuild) {
{},
{"AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
+ vector<move> exp_moves = {
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, MoveBuiltGroupTrue) {
@@ -169,14 +167,14 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) {
{},
{"2C", "AC"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(1, 0, 1),
- mv(1, 0, 2)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 1, 0, 1),
+ move(move::mtype::built_group, 1, 0, 2)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, MoveBuiltGroupFalse) {
@@ -188,13 +186,13 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) {
{},
{"AC", "2C"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(1, 0, 1)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 1, 0, 1)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, Foundations) {
@@ -209,16 +207,16 @@ TEST(LegalMoveGen, Foundations) {
{"AS"},
{"AD"},
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4, 0),
- mv(5, 1),
- mv(6, 2),
- mv(7, 3)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 4, 0),
+ move(move::mtype::regular, 5, 1),
+ move(move::mtype::regular, 6, 2),
+ move(move::mtype::regular, 7, 3)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, FoundationsRemovable) {
@@ -234,13 +232,13 @@ TEST(LegalMoveGen, FoundationsRemovable) {
{},
{}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(0, 4)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 0, 4)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, Cells) {
@@ -252,15 +250,15 @@ TEST(LegalMoveGen, Cells) {
{"3D"}, {}, // The cells
{"4H"}
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(0, 1),
- mv(0, 2),
- mv(2, 1)
+ vector<move> exp_moves = {
+ move(move::mtype::regular, 0, 1),
+ move(move::mtype::regular, 0, 2),
+ move(move::mtype::regular, 2, 1)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, StockDealToWaste) {
@@ -276,13 +274,13 @@ TEST(LegalMoveGen, StockDealToWaste) {
{}, // The waste
{}, {}, {} // The tableau piles
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4, 5)
+ vector<move> exp_moves = {
+ move(move::mtype::stock_to_waste, 4, 5)
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}
TEST(LegalMoveGen, StockDealToTableau) {
@@ -297,41 +295,11 @@ TEST(LegalMoveGen, StockDealToTableau) {
{"AC", "AD"}, // The stock
{"3H"}, {"5D"}, {"7C"} // The tableau piles
});
- vector<mv> actual_moves = gs.get_legal_moves();
+ vector<move> actual_moves = gs.get_legal_moves();
- vector<mv> exp_moves = {
- mv(4, 255, 2) // Special stock-to-tableau syntax
+ vector<move> exp_moves = {
+ move(move::mtype::stock_to_tableau, 0, 0, 2) // Special stock-to-tableau syntax
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
-}
-
-
-
-bool moves_eq(vector<mv>& exp_moves, vector<mv>& actual_moves) {
- if (exp_moves.size() != actual_moves.size()) return false;
-
- for (mv 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 mv& m) {
- return os << "move:(" << int(m.from)
- << "," << int(m.to)
- << "," << int(m.count)
- << ")";
-}
-
-ostream& operator <<(ostream& os, const vector<mv>& moves) {
- for (const mv m : moves) {
- os << m << ",\n";
- }
- return os;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}