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.cpp40
-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/legal_move_gen_test.cpp62
8 files changed, 326 insertions, 63 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 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;
+}
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..0bdff4d
--- /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(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 2),
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(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(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(2, 0, 2),
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 0, 2),
+ move(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(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 2),
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(1, 4, 3),
+
+ move(2, 0, 2),
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 0, 2),
+ move(3, 0, 3),
+ move(3, 4, 2),
+ move(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(1, 0, 1),
+ move(2, 0, 1),
+ move(3, 0, 1),
+ move(1, 4, 1),
+ move(2, 4, 1),
+ move(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(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 3),
+ move(1, 4, 2),
+ move(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(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(2, 0, 3),
+ move(2, 4, 2),
+ move(2, 4, 3),
+ move(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(1, 4, 1),
+ move(2, 4, 1),
+ move(3, 4, 1),
+ move(0, 4, 1),
+
+ // Built pile moves
+ move(1, 0, 3),
+ move(2, 0, 3),
+ move(3, 0, 3),
+
+ move(1, 4, 2),
+ move(1, 4, 3),
+
+ move(2, 4, 2),
+ move(2, 4, 3),
+
+ move(3, 4, 2),
+ move(3, 4, 3),
+ }
+ );
+}
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index 84755f6..f8c9a63 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -16,10 +16,6 @@ using std::vector;
using std::ostream;
using std::initializer_list;
-bool moves_eq(vector<move>&, vector<move>&);
-ostream& operator <<(ostream&, const move&);
-ostream& operator <<(ostream&, const vector<move>&);
-
TEST(LegalMoveGen, BuildPolAnySuit) {
sol_rules sr;
sr.build_pol = pol::ANY_SUIT;
@@ -41,7 +37,7 @@ TEST(LegalMoveGen, BuildPolAnySuit) {
move(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) {
@@ -63,7 +59,7 @@ TEST(LegalMoveGen, BuildPolRedBlack) {
move(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) {
@@ -84,7 +80,7 @@ TEST(LegalMoveGen, BuildPolSameSuit) {
move(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) {
@@ -104,7 +100,7 @@ TEST(LegalMoveGen, BuildPolNoBuild) {
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) {
@@ -122,7 +118,7 @@ TEST(LegalMoveGen, SpacesPolAny) {
move(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) {
@@ -141,7 +137,7 @@ TEST(LegalMoveGen, SpacesPolKings) {
move(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) {
@@ -158,7 +154,7 @@ TEST(LegalMoveGen, SpacesPolNoBuild) {
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) {
@@ -177,7 +173,7 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) {
move(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) {
@@ -195,7 +191,7 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) {
move(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) {
@@ -219,7 +215,7 @@ TEST(LegalMoveGen, Foundations) {
move(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) {
@@ -241,7 +237,7 @@ TEST(LegalMoveGen, FoundationsRemovable) {
move(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) {
@@ -261,7 +257,7 @@ TEST(LegalMoveGen, Cells) {
move(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) {
@@ -283,7 +279,7 @@ TEST(LegalMoveGen, StockDealToWaste) {
move(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) {
@@ -304,35 +300,5 @@ TEST(LegalMoveGen, StockDealToTableau) {
move(4, 255, 2) // Special stock-to-tableau syntax
};
- ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
-}
-
-
-
-bool 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;
+ ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves;
}