diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/integration_tests/canfield_test.cpp | 111 | ||||
| -rw-r--r-- | src/test/resources/canfield/ComplexSolvable.json | 11 | ||||
| -rw-r--r-- | src/test/resources/canfield/ComplexUnsolvable.json | 11 | ||||
| -rw-r--r-- | src/test/resources/canfield/SimpleSolvable.json | 13 | ||||
| -rw-r--r-- | src/test/resources/canfield/SimpleUnsolvable.json | 11 | ||||
| -rw-r--r-- | src/test/test_helper.cpp | 8 | ||||
| -rw-r--r-- | src/test/test_helper.h | 2 | ||||
| -rw-r--r-- | src/test/unit_tests/built_group_move_gen_test.cpp | 19 | ||||
| -rw-r--r-- | src/test/unit_tests/face_up_cards_test.cpp | 23 | ||||
| -rw-r--r-- | src/test/unit_tests/legal_move_gen_test.cpp | 5 |
10 files changed, 171 insertions, 43 deletions
diff --git a/src/test/integration_tests/canfield_test.cpp b/src/test/integration_tests/canfield_test.cpp index 6a045ea..006f4fb 100644 --- a/src/test/integration_tests/canfield_test.cpp +++ b/src/test/integration_tests/canfield_test.cpp @@ -5,8 +5,14 @@ #include <gtest/gtest.h> #include "../test_helper.h" +#include "../../main/input-output/input/json-parsing/rules_parser.h" +#include "../../main/game/search-state/game_state.h" + +using std::vector; typedef test_helper th; +typedef game_state::streamliner_options so; +typedef std::initializer_list<std::initializer_list<std::string>> string_il; const static std::string path = "resources/canfield/"; const static std::string type = "simple-canfield"; @@ -26,3 +32,108 @@ TEST(Canfield, SimpleUnsolvable) { TEST(Canfield, ComplexUnsolvable) { EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type)); } + +TEST(Canfield, FoundationSingleCard) { + sol_rules sr = rules_parser::from_preset("canfield"); + game_state gs(sr, 0, so::NONE); + + ASSERT_EQ(1, test_helper::cards_in_founds(gs)); +} + +TEST(Canfield, FoundationWraps) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"3C"},{},{},{}, // Foundations + {},{}, // Stock-waste + {}, // Reserve + {"AC"},{},{} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = { + move(move::mtype::regular, 7, 0, 1) + }; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +TEST(Canfield, MoveWholePile) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"3C"},{},{},{}, // Foundations + {},{}, // Stock-waste + {}, // Reserve + {"3H","2S","AH"},{"AS"},{"2D"} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = { + move(move::mtype::built_group, 7, 8, 3), + move(move::mtype::built_group, 8, 9, 1), + }; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +TEST(Canfield, MoveWholePileNotSpace) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"3C"},{},{},{}, // Foundations + {},{}, // Stock-waste + {}, // Reserve + {"2H","3S","AH"},{},{"2D"} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = {}; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +TEST(Canfield, AutoReserve) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"2C"},{},{},{}, // Foundations + {"3D","2D"},{}, // Stock-waste + {"3H"}, // Reserve + {"2H","3S","AH"},{},{"AC"} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = {}; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; + + boost::optional<move> actual_dom_move = gs.get_dominance_move(); + boost::optional<move> exp_dom_move = move(move::mtype::dominance, 6, 8, 1); + + ASSERT_EQ(exp_dom_move, actual_dom_move) << *actual_dom_move; +} + +TEST(Canfield, AutoReserveThenWaste) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"3C"},{},{},{}, // Foundations + {"2D"},{"2S"}, // Stock-waste + {}, // Reserve + {"2H","3S","AH"},{},{"AD"} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = { + move(move::mtype::stock_k_plus, 4, 8, 0), + move(move::mtype::stock_k_plus, 4, 8, 1) + }; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; + + boost::optional<move> actual_dom_move = gs.get_dominance_move(); + boost::optional<move> exp_dom_move = boost::none; + + ASSERT_EQ(exp_dom_move, actual_dom_move) << *actual_dom_move; +} diff --git a/src/test/resources/canfield/ComplexSolvable.json b/src/test/resources/canfield/ComplexSolvable.json index b5c9253..2a4c252 100644 --- a/src/test/resources/canfield/ComplexSolvable.json +++ b/src/test/resources/canfield/ComplexSolvable.json @@ -1,9 +1,10 @@ { + "foundations": ["2C"], "tableau piles": [ - ["AC","2C","3C"], - ["AD","2D","3D"], - ["3S","AS","3H"] + ["3D"], + ["3H"], + ["3S"] ], - "stock": ["2H"], - "reserve": ["AH","2S"] + "reserve": ["AC","2S","3C"], + "stock": ["AH","2H","AD","AS","2D"] }
\ No newline at end of file diff --git a/src/test/resources/canfield/ComplexUnsolvable.json b/src/test/resources/canfield/ComplexUnsolvable.json index 9391caf..297d06b 100644 --- a/src/test/resources/canfield/ComplexUnsolvable.json +++ b/src/test/resources/canfield/ComplexUnsolvable.json @@ -1,9 +1,10 @@ { + "foundations": ["2C"], "tableau piles": [ - ["AC","2H","2D"], - ["AD","3D","3C"], - ["2S","AS","3H"] + ["AS","3D"], + ["AC","3H"], + ["3S"] ], - "stock": ["2C"], - "reserve": ["AH","3S"] + "reserve": ["AH","2S","3C"], + "stock": ["AD","2H","2D"] }
\ No newline at end of file diff --git a/src/test/resources/canfield/SimpleSolvable.json b/src/test/resources/canfield/SimpleSolvable.json index 4e998ea..3353b5c 100644 --- a/src/test/resources/canfield/SimpleSolvable.json +++ b/src/test/resources/canfield/SimpleSolvable.json @@ -1,9 +1,10 @@ { + "foundations": ["2C"], "tableau piles": [ - ["3C","2C","AC"], - ["3D","2D","AD"], - ["3H","3S","AH"] + ["2S"], + ["AC"], + ["3D"] ], - "stock": ["2H"], - "reserve": ["2S","AS"] -} + "reserve": ["AH","3S"], + "stock": ["2H","AS","3H","2D","3C","AD"] +}
\ No newline at end of file diff --git a/src/test/resources/canfield/SimpleUnsolvable.json b/src/test/resources/canfield/SimpleUnsolvable.json index e8a1e3e..440c358 100644 --- a/src/test/resources/canfield/SimpleUnsolvable.json +++ b/src/test/resources/canfield/SimpleUnsolvable.json @@ -1,9 +1,10 @@ { + "foundations": ["2C"], "tableau piles": [ - ["AC","2C","3C"], - ["AD","2D","3D"], - ["AH","AS","3H"] + ["3D"], + ["3H"], + ["3S"] ], - "stock": ["2H"], - "reserve": ["2S","3S"] + "reserve": ["2S","AS"], + "stock": ["AC","2H","3C","AH","AD","2D"] }
\ No newline at end of file diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index c4f902e..33a81ca 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -124,6 +124,14 @@ void test_helper::k_plus_stock_test ASSERT_EQ(gs.get_data(), game_state(sr, piles).get_data()) << gs; } +uint8_t test_helper::cards_in_founds(game_state& gs) { + uint8_t sz = 0; + for (auto found : gs.foundations) { + sz += gs.piles[found].size(); + } + return sz; +} + ostream& operator <<(ostream& os, const move& m) { return os << "move:(" << int(m.from) << "," << int(m.to) diff --git a/src/test/test_helper.h b/src/test/test_helper.h index 564310e..89d28cb 100644 --- a/src/test/test_helper.h +++ b/src/test/test_helper.h @@ -11,6 +11,7 @@ #include "../main/game/card.h" #include "../main/game/pile.h" #include "../main/game/move.h" +#include "../main/game/search-state/game_state.h" class test_helper { public: @@ -30,6 +31,7 @@ public: , card ); static bool moves_eq(std::vector<move>&, std::vector<move>&); + static uint8_t cards_in_founds(game_state&); }; std::ostream& operator <<(std::ostream&, const move&); diff --git a/src/test/unit_tests/built_group_move_gen_test.cpp b/src/test/unit_tests/built_group_move_gen_test.cpp index 7bc7f46..b16a874 100644 --- a/src/test/unit_tests/built_group_move_gen_test.cpp +++ b/src/test/unit_tests/built_group_move_gen_test.cpp @@ -10,6 +10,7 @@ typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; +typedef sol_rules::built_group_type bgt; using std::vector; using std::ostream; @@ -19,7 +20,7 @@ TEST(BuiltGroupMoveGen, SameSuitEmpty) { sol_rules sr; sr.tableau_pile_count = 5; sr.built_group_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -52,7 +53,7 @@ TEST(BuiltGroupMoveGen, RedBlackEmpty) { sol_rules sr; sr.tableau_pile_count = 5; sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -88,7 +89,7 @@ TEST(BuiltGroupMoveGen, AnySuitEmpty) { sol_rules sr; sr.tableau_pile_count = 5; sr.built_group_pol = pol::ANY_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -131,7 +132,7 @@ TEST(BuiltGroupMoveGen, CantMove) { sol_rules sr; sr.tableau_pile_count = 5; sr.built_group_pol = pol::ANY_SUIT; - sr.move_built_group = false; + sr.move_built_group = bgt::NO; test_helper::expected_moves_test( sr, @@ -159,7 +160,7 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { sr.tableau_pile_count = 6; sr.build_pol = pol::SAME_SUIT; sr.built_group_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -194,7 +195,7 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { sr.tableau_pile_count = 6; sr.build_pol = pol::RED_BLACK; sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -229,7 +230,7 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { sr.tableau_pile_count = 6; sr.build_pol = pol::ANY_SUIT; sr.built_group_pol = pol::ANY_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; test_helper::expected_moves_test( sr, @@ -276,7 +277,7 @@ TEST(BuiltGroupMoveGen, KingsOnly) { sr.tableau_pile_count = 5; sr.build_pol = pol::SAME_SUIT; sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.spaces_pol = s_pol::KINGS; test_helper::expected_moves_test( @@ -301,7 +302,7 @@ TEST(BuiltGroupMoveGen, NoBuild) { sr.tableau_pile_count = 5; sr.build_pol = pol::SAME_SUIT; sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.spaces_pol = s_pol::NO_BUILD; test_helper::expected_moves_test( diff --git a/src/test/unit_tests/face_up_cards_test.cpp b/src/test/unit_tests/face_up_cards_test.cpp index 5bf65cb..eb828a0 100644 --- a/src/test/unit_tests/face_up_cards_test.cpp +++ b/src/test/unit_tests/face_up_cards_test.cpp @@ -12,6 +12,7 @@ typedef sol_rules::build_policy pol; typedef sol_rules::face_up_policy fu; typedef move::mtype mt; +typedef sol_rules::built_group_type bgt; using std::vector; using std::ostream; @@ -27,7 +28,7 @@ TEST(FaceUpCards, CapsFaceUpIfFaceUpNotAll) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -48,7 +49,7 @@ TEST(FaceUpCards, IgnoreCapsIfFaceUpAll) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::ALL; string_il piles = { @@ -69,7 +70,7 @@ TEST(FaceUpCards, MoveTurnsFaceUp) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -101,7 +102,7 @@ TEST(FaceUpCards, BuiltGroupMoveTurnsFaceUp) { sr.tableau_pile_count = 2; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -133,7 +134,7 @@ TEST(FaceUpCards, MoveAlreadyFaceUpNoChange) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -165,7 +166,7 @@ TEST(FaceUpCards, FaceDownNoBuiltGroup) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; test_helper::expected_moves_test( @@ -188,7 +189,7 @@ TEST(FaceUpCards, FaceUpBuiltGroup) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; test_helper::expected_moves_test( @@ -215,7 +216,7 @@ TEST(FaceUpCards, FaceUpBuiltGroup2Not3) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; test_helper::expected_moves_test( @@ -241,7 +242,7 @@ TEST(FaceUpCards, UndoTurnsBackFaceDown) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -265,7 +266,7 @@ TEST(FaceUpCards, UndoBuiltGroupTurnsBackFaceDown) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::SAME_SUIT; sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { @@ -290,7 +291,7 @@ TEST(FaceUpCards, CacheEncodesFaceDown) { sr.tableau_pile_count = 3; sr.built_group_pol = pol::RED_BLACK; sr.build_pol = pol::RED_BLACK; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.face_up = fu::TOP_CARDS; string_il piles = { diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp index 4625163..a948bba 100644 --- a/src/test/unit_tests/legal_move_gen_test.cpp +++ b/src/test/unit_tests/legal_move_gen_test.cpp @@ -12,6 +12,7 @@ typedef sol_rules::build_policy pol; typedef sol_rules::spaces_policy s_pol; typedef sol_rules::stock_deal_type sdt; +typedef sol_rules::built_group_type bgt; using std::vector; using std::ostream; @@ -162,7 +163,7 @@ TEST(LegalMoveGen, SpacesPolNoBuild) { TEST(LegalMoveGen, MoveBuiltGroupTrue) { sol_rules sr; - sr.move_built_group = true; + sr.move_built_group = bgt::YES; sr.tableau_pile_count = 2; game_state gs(sr, string_il{ @@ -181,7 +182,7 @@ TEST(LegalMoveGen, MoveBuiltGroupTrue) { TEST(LegalMoveGen, MoveBuiltGroupFalse) { sol_rules sr; - sr.move_built_group = false; + sr.move_built_group = bgt::NO; sr.tableau_pile_count = 2; game_state gs(sr, string_il{ |
