aboutsummaryrefslogtreecommitdiff
path: root/src/test/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/unit_tests')
-rw-r--r--src/test/unit_tests/face_up_cards_test.cpp108
-rw-r--r--src/test/unit_tests/global_cache_test.cpp55
-rw-r--r--src/test/unit_tests/legal_move_gen_test.cpp32
3 files changed, 105 insertions, 90 deletions
diff --git a/src/test/unit_tests/face_up_cards_test.cpp b/src/test/unit_tests/face_up_cards_test.cpp
index 7c6228b..5bf65cb 100644
--- a/src/test/unit_tests/face_up_cards_test.cpp
+++ b/src/test/unit_tests/face_up_cards_test.cpp
@@ -15,10 +15,11 @@ typedef move::mtype mt;
using std::vector;
using std::ostream;
-using std::initializer_list;
-#define ASSERT_FACE_UP(card) ASSERT_TRUE(card.is_face_up()) << card.to_string() << " should be face up"
-#define ASSERT_FACE_DOWN(card) ASSERT_FALSE(card.is_face_up()) << card.to_string() << " should be face down"
+typedef std::initializer_list<std::initializer_list<std::string>> string_il;
+
+#define ASSERT_FACE_UP(card) ASSERT_FALSE(card.is_face_down()) << card.to_string() << " should be face up"
+#define ASSERT_FACE_DOWN(card) ASSERT_TRUE(card.is_face_down()) << card.to_string() << " should be face down"
TEST(FaceUpCards, CapsFaceUpIfFaceUpNotAll) {
@@ -29,7 +30,7 @@ TEST(FaceUpCards, CapsFaceUpIfFaceUpNotAll) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"3S"},
{"2s","AS"},
{}
@@ -50,7 +51,7 @@ TEST(FaceUpCards, IgnoreCapsIfFaceUpAll) {
sr.move_built_group = true;
sr.face_up = fu::ALL;
- initializer_list<pile> piles = {
+ string_il piles = {
{"3S"},
{"2s","AS"},
{}
@@ -71,14 +72,24 @@ TEST(FaceUpCards, MoveTurnsFaceUp) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"3S"},
{"2s","AS"}, // from
{} // to
};
+ test_helper::expected_moves_test(
+ sr,
+ piles,
+ {
+ // Regular moves
+ move(move::mtype::regular, 0, 2, 1, false),
+ move(move::mtype::regular, 1, 2, 1, true)
+ }
+ );
+
game_state gs(sr, piles);
- gs.make_move(move(mt::regular, 1, 2));
+ gs.make_move(move(mt::regular, 1, 2, 1, true));
ASSERT_FACE_UP(gs.get_data()[0][0]);
ASSERT_FACE_UP(gs.get_data()[1][0]);
@@ -87,25 +98,34 @@ TEST(FaceUpCards, MoveTurnsFaceUp) {
TEST(FaceUpCards, BuiltGroupMoveTurnsFaceUp) {
sol_rules sr;
- sr.tableau_pile_count = 3;
+ sr.tableau_pile_count = 2;
sr.built_group_pol = pol::SAME_SUIT;
sr.build_pol = pol::SAME_SUIT;
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
- {"4S"},
+ string_il piles = {
{"3s","2S","AS"}, // from
{} // to
};
+ test_helper::expected_moves_test(
+ sr,
+ piles,
+ {
+ // Regular moves
+ move(move::mtype::regular, 0, 1, 1, false),
+ // Built-group moves
+ move(move::mtype::built_group, 0, 1, 2, true)
+ }
+ );
+
game_state gs(sr, piles);
- gs.make_move(move(mt::built_group, 1, 2, 2));
+ gs.make_move(move(mt::built_group, 0, 1, 2, true));
ASSERT_FACE_UP(gs.get_data()[0][0]);
ASSERT_FACE_UP(gs.get_data()[1][0]);
- ASSERT_FACE_UP(gs.get_data()[2][0]);
- ASSERT_FACE_UP(gs.get_data()[2][1]);
+ ASSERT_FACE_UP(gs.get_data()[1][1]);
}
TEST(FaceUpCards, MoveAlreadyFaceUpNoChange) {
@@ -116,14 +136,24 @@ TEST(FaceUpCards, MoveAlreadyFaceUpNoChange) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"3S"},
- {"2S","AS"}, // from
+ {"2s","AS"}, // from
{} // to
};
+ test_helper::expected_moves_test(
+ sr,
+ piles,
+ {
+ // Regular moves
+ move(move::mtype::regular, 0, 2, 1, false),
+ move(move::mtype::regular, 1, 2, 1, true)
+ }
+ );
+
game_state gs(sr, piles);
- gs.make_move(move(mt::regular, 1, 2));
+ gs.make_move(move(mt::regular, 1, 2, 1, true));
ASSERT_FACE_UP(gs.get_data()[0][0]);
ASSERT_FACE_UP(gs.get_data()[1][0]);
@@ -138,12 +168,6 @@ TEST(FaceUpCards, FaceDownNoBuiltGroup) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
- {"3S"},
- {"2s","AS"},
- {}
- };
-
test_helper::expected_moves_test(
sr,
{
@@ -153,8 +177,8 @@ TEST(FaceUpCards, FaceDownNoBuiltGroup) {
},
{
// Regular moves
- move(move::mtype::regular, 0, 2, 1),
- move(move::mtype::regular, 1, 2, 1),
+ move(move::mtype::regular, 0, 2, 1, false),
+ move(move::mtype::regular, 1, 2, 1, true),
}
);
}
@@ -167,12 +191,6 @@ TEST(FaceUpCards, FaceUpBuiltGroup) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
- {"3S"},
- {"2s","AS"},
- {}
- };
-
test_helper::expected_moves_test(
sr,
{
@@ -200,12 +218,6 @@ TEST(FaceUpCards, FaceUpBuiltGroup2Not3) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
- {"3S"},
- {"2s","AS"},
- {}
- };
-
test_helper::expected_moves_test(
sr,
{
@@ -215,11 +227,11 @@ TEST(FaceUpCards, FaceUpBuiltGroup2Not3) {
},
{
// Regular moves
- move(mt::regular, 0, 2, 1),
- move(mt::regular, 1, 2, 1),
+ move(mt::regular, 0, 2, 1, false),
+ move(mt::regular, 1, 2, 1, false),
// Built group moves
- move(mt::built_group, 1, 2, 2)
+ move(mt::built_group, 1, 2, 2, true)
}
);
}
@@ -232,14 +244,14 @@ TEST(FaceUpCards, UndoTurnsBackFaceDown) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"3S"},
{"2s","AS"}, // from
{} // to
};
game_state gs(sr, piles);
- move m = move(mt::regular, 1, 2);
+ move m = move(mt::regular, 1, 2, 1, true);
gs.make_move(m);
gs.undo_move(m);
@@ -256,14 +268,14 @@ TEST(FaceUpCards, UndoBuiltGroupTurnsBackFaceDown) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"4S"},
{"3s","2S","AS"}, // from
{} // to
};
game_state gs(sr, piles);
- move m = move(mt::built_group, 1, 2, 2);
+ move m = move(mt::built_group, 1, 2, 2, true);
gs.make_move(m);
gs.undo_move(m);
@@ -281,7 +293,7 @@ TEST(FaceUpCards, CacheEncodesFaceDown) {
sr.move_built_group = true;
sr.face_up = fu::TOP_CARDS;
- initializer_list<pile> piles = {
+ string_il piles = {
{"2C"},
{"2s","AH"},
{}
@@ -291,19 +303,19 @@ TEST(FaceUpCards, CacheEncodesFaceDown) {
lru_cache cache(gs, 1000);
bool new_state;
- gs.make_move(move(mt::regular, 1, 2));
+ gs.make_move(move(mt::regular, 1, 2, 1, true));
new_state = cache.insert(gs).second;
ASSERT_TRUE(new_state) << "AH to empty pile";
- gs.make_move(move(mt::regular, 2, 1));
+ gs.make_move(move(mt::regular, 2, 1, 1, false));
new_state = cache.insert(gs).second;
ASSERT_TRUE(new_state) << "AH back to face-up 2S";
- gs.make_move(move(mt::regular, 1, 0));
+ gs.make_move(move(mt::regular, 1, 0, 1, false));
new_state = cache.insert(gs).second;
ASSERT_TRUE(new_state) << "AH to 2C";
- gs.make_move(move(mt::regular, 0, 1));
+ gs.make_move(move(mt::regular, 0, 1, 1, false));
new_state = cache.insert(gs).second;
ASSERT_FALSE(new_state) << "AH to 2S";
}
diff --git a/src/test/unit_tests/global_cache_test.cpp b/src/test/unit_tests/global_cache_test.cpp
index cd3c686..93ef105 100644
--- a/src/test/unit_tests/global_cache_test.cpp
+++ b/src/test/unit_tests/global_cache_test.cpp
@@ -9,69 +9,70 @@
#include "../../main/game/global_cache.h"
typedef sol_rules::build_policy pol;
+typedef std::initializer_list<std::initializer_list<std::string>> string_il;
TEST(GlobalCache, CommutativeTableauPiles) {
sol_rules rules;
rules.tableau_pile_count = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
- game_state gs(rules, std::initializer_list<pile>{{},{},{}});
+ game_state gs(rules, string_il{{},{},{}});
lru_cache cache(gs, 1000);
- cache.insert (game_state(rules, {{card("AC")},{card("2D")},{card("3H")}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{card("2D")},{card("3H")},{card("AC")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{card("3H")},{card("2D")},{card("3H")}})));
+ cache.insert (game_state(rules, {{"AC"},{"2D"},{"3H"}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{"2D"},{"3H"},{"AC"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{"3H"},{"2D"},{"3H"}})));
// Test with empty piles
cache.clear();
- cache.insert (game_state(rules, {{card("4C")},{card("5D")},{}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{},{card("4C")},{card("5D")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{},{card("4C")},{}})));
+ cache.insert (game_state(rules, {{"4C"},{"5D"},{}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{},{"4C"},{"5D"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{},{"4C"},{}})));
// Test with piles of size > 1
cache.clear();
- cache.insert (game_state(rules, {{card("6C"),card("7D")},{card("8C")},{card("9D")}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{card("8C")},{card("6C"),card("7D")},{card("9D")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{card("8C")},{card("6C"),card("KD")},{card("9D")}})));
+ cache.insert (game_state(rules, {{"6C","7D"},{"8C"},{"9D"}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{"8C"},{"6C","7D"},{"9D"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{"8C"},{"6C","KD"},{"9D"}})));
}
TEST(GlobalCache, CommutativeReserve) {
sol_rules rules;
rules.reserve_size = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
- game_state gs(rules, std::initializer_list<pile>{{},{},{}});
+ game_state gs(rules, string_il{{},{},{}});
lru_cache cache(gs, 1000);
- cache.insert (game_state(rules, {{card("AC")},{card("2D")},{card("3H")}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{card("2D")},{card("3H")},{card("AC")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{card("3H")},{card("2D")},{card("3H")}})));
+ cache.insert (game_state(rules, {{"AC"},{"2D"},{"3H"}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{"2D"},{"3H"},{"AC"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{"3H"},{"2D"},{"3H"}})));
// Test with empty piles
cache.clear();
- cache.insert (game_state(rules, {{card("4C")},{card("5D")},{}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{},{card("4C")},{card("5D")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{},{card("4C")},{}})));
+ cache.insert (game_state(rules, {{"4C"},{"5D"},{}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{},{"4C"},{"5D"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{},{"4C"},{}})));
// Test with piles of size > 1
cache.clear();
- cache.insert (game_state(rules, {{card("6C"),card("7D")},{card("8C")},{card("9D")}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{card("8C")},{card("6C"),card("7D")},{card("9D")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{card("8C")},{card("6C"),card("KD")},{card("9D")}})));
+ cache.insert (game_state(rules, {{"6C","7D"},{"8C"},{"9D"}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{"8C"},{"6C","7D"},{"9D"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{"8C"},{"6C","KD"},{"9D"}})));
}
TEST(GlobalCache, CommutativeCells) {
sol_rules rules;
rules.cells = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
- game_state gs(rules, std::initializer_list<pile>{{},{},{}});
+ game_state gs(rules, string_il{{},{},{}});
lru_cache cache(gs, 1000);
- cache.insert (game_state(rules, {{card("AC")},{card("2D")},{card("3H")}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{card("2D")},{card("3H")},{card("AC")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{card("3H")},{card("2D")},{card("3H")}})));
+ cache.insert (game_state(rules, {{"AC"},{"2D"},{"3H"}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{"2D"},{"3H"},{"AC"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{"3H"},{"2D"},{"3H"}})));
// Test with empty piles
cache.clear();
- cache.insert (game_state(rules, {{card("4C")},{card("5D")},{}}));
- ASSERT_TRUE (cache.contains(game_state(rules, {{},{card("4C")},{card("5D")}})));
- ASSERT_FALSE(cache.contains(game_state(rules, {{},{card("4C")},{}})));
+ cache.insert (game_state(rules, {{"4C"},{"5D"},{}}));
+ ASSERT_TRUE (cache.contains(game_state(rules, {{},{"4C"},{"5D"}})));
+ ASSERT_FALSE(cache.contains(game_state(rules, {{},{"4C"},{}})));
}
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index de6733e..6ea73d5 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -15,14 +15,16 @@ typedef sol_rules::stock_deal_type sdt;
using std::vector;
using std::ostream;
-using std::initializer_list;
+
+typedef std::initializer_list<std::initializer_list<std::string>> string_il;
+
TEST(LegalMoveGen, BuildPolAnySuit) {
sol_rules sr;
sr.build_pol = pol::ANY_SUIT;
sr.tableau_pile_count = 5;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"2C"},
{"2H"},
{"2D"},
@@ -46,7 +48,7 @@ TEST(LegalMoveGen, BuildPolRedBlack) {
sr.build_pol = pol::RED_BLACK;
sr.tableau_pile_count = 5;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"2C"},
{"2H"},
{"2S"},
@@ -68,7 +70,7 @@ TEST(LegalMoveGen, BuildPolSameSuit) {
sr.build_pol = pol::SAME_SUIT;
sr.tableau_pile_count = 5;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"2C"},
{"2H"},
{"2S"},
@@ -89,7 +91,7 @@ TEST(LegalMoveGen, BuildPolNoBuild) {
sr.build_pol = pol::NO_BUILD;
sr.tableau_pile_count = 5;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"2C"},
{"2H"},
{"2S"},
@@ -109,7 +111,7 @@ TEST(LegalMoveGen, SpacesPolAny) {
sr.spaces_pol = s_pol::ANY;
sr.tableau_pile_count = 2;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{},
{"AC"}
});
@@ -127,7 +129,7 @@ TEST(LegalMoveGen, SpacesPolKings) {
sr.spaces_pol = s_pol::KINGS;
sr.tableau_pile_count = 3;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{},
{"AC"},
{"KD"}
@@ -146,7 +148,7 @@ TEST(LegalMoveGen, SpacesPolNoBuild) {
sr.spaces_pol = s_pol::NO_BUILD;
sr.tableau_pile_count = 2;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{},
{"AC"}
});
@@ -163,7 +165,7 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) {
sr.move_built_group = true;
sr.tableau_pile_count = 2;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{},
{"2C", "AC"}
});
@@ -182,7 +184,7 @@ TEST(LegalMoveGen, MoveBuiltGroupFalse) {
sr.move_built_group = false;
sr.tableau_pile_count = 2;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{},
{"AC", "2C"}
});
@@ -200,7 +202,7 @@ TEST(LegalMoveGen, Foundations) {
sr.foundations = true;
sr.tableau_pile_count = 4;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{}, {}, {}, {},
{"AC"},
{"AH"},
@@ -225,7 +227,7 @@ TEST(LegalMoveGen, FoundationsRemovable) {
sr.foundations_removable = true;
sr.tableau_pile_count = 1;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"AC","2C","3C"}, // Without a few cards here dominance logic blocks
{}, // removing from foundation
{},
@@ -246,7 +248,7 @@ TEST(LegalMoveGen, Cells) {
sr.cells = 2;
sr.tableau_pile_count = 1;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{"3D"}, {}, // The cells
{"4H"}
});
@@ -267,7 +269,7 @@ TEST(LegalMoveGen, StockDealToWaste) {
sr.stock_size = 2;
sr.stock_deal_t = sdt::WASTE;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{}, {}, {}, {}, // The foundations
{"AC", "AD"}, // The stock
{}, // The waste
@@ -289,7 +291,7 @@ TEST(LegalMoveGen, StockDealToTableau) {
sr.stock_size = 2;
sr.stock_deal_t = sdt::TABLEAU_PILES;
- game_state gs(sr, initializer_list<pile>{
+ game_state gs(sr, string_il{
{}, {}, {}, {}, // The foundations
{"AC", "AD"}, // The stock
{"3H"}, {"5D"}, {"7C"} // The tableau piles