diff options
| author | Ian Gent | 2018-06-26 11:21:28 +0100 |
|---|---|---|
| committer | Ian Gent | 2018-06-26 11:21:28 +0100 |
| commit | 9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb (patch) | |
| tree | c98a9fb4bac9d74a059987929f3dfb93f7e5a8c3 /src/test | |
| parent | Raglan deal (diff) | |
| parent | Merge pull request #69 from thecharlesblake/correct-klondike (diff) | |
| download | metasol-9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb.tar.gz metasol-9ed82b8bbdc1d7b0265a9009950a4dc4916d91bb.zip | |
Merge branch ‘master’ of github.com:thecharlesblake/Solvitaire
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/test_helper.cpp | 6 | ||||
| -rw-r--r-- | src/test/test_helper.h | 2 | ||||
| -rw-r--r-- | src/test/unit_tests/built_group_move_gen_test.cpp | 56 | ||||
| -rw-r--r-- | src/test/unit_tests/face_up_cards_test.cpp | 273 |
4 files changed, 305 insertions, 32 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index ab9e0cb..e1aa0a7 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -62,9 +62,9 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, ASSERT_TRUE(i->child_moves.empty()); } -void test_helper::run_built_group_test(sol_rules sr, - initializer_list<pile> piles, - vector<move> exp_moves) { +void test_helper::expected_moves_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(); diff --git a/src/test/test_helper.h b/src/test/test_helper.h index 463a935..0690d0e 100644 --- a/src/test/test_helper.h +++ b/src/test/test_helper.h @@ -17,7 +17,7 @@ public: static bool is_solvable(const std::string&, const std::string&); 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 void expected_moves_test(sol_rules sr, std::initializer_list<pile>, std::vector<move>); static bool moves_eq(std::vector<move>&, std::vector<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 34e2b07..37a2cf0 100644 --- a/src/test/unit_tests/built_group_move_gen_test.cpp +++ b/src/test/unit_tests/built_group_move_gen_test.cpp @@ -20,13 +20,13 @@ TEST(BuiltGroupMoveGen, SameSuitEmpty) { sr.built_group_pol = pol::SAME_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -53,13 +53,13 @@ TEST(BuiltGroupMoveGen, RedBlackEmpty) { sr.built_group_pol = pol::RED_BLACK; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -89,13 +89,13 @@ TEST(BuiltGroupMoveGen, AnySuitEmpty) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -132,13 +132,13 @@ TEST(BuiltGroupMoveGen, CantMove) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = false; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -159,13 +159,13 @@ TEST(BuiltGroupMoveGen, SameSuitOccupied) { sr.built_group_pol = pol::SAME_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -189,13 +189,13 @@ TEST(BuiltGroupMoveGen, RedBlackOccupied) { sr.built_group_pol = pol::RED_BLACK; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { @@ -220,13 +220,13 @@ TEST(BuiltGroupMoveGen, AnySuitOccupied) { sr.built_group_pol = pol::ANY_SUIT; sr.move_built_group = true; - test_helper::run_built_group_test( + test_helper::expected_moves_test( sr, { {"4C"}, - {"3C","2C","AC"}, // Same suit - {"3H","2S","AH"}, // Red black - {"3D","2D","AS"}, // Any suit + {"3C", "2C", "AC"}, // Same suit + {"3H", "2S", "AH"}, // Red black + {"3D", "2D", "AS"}, // Any suit {} }, { diff --git a/src/test/unit_tests/face_up_cards_test.cpp b/src/test/unit_tests/face_up_cards_test.cpp new file mode 100644 index 0000000..6e2d6a3 --- /dev/null +++ b/src/test/unit_tests/face_up_cards_test.cpp @@ -0,0 +1,273 @@ +// +// 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; +typedef sol_rules::face_up_policy fu; +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" + + +TEST(FaceUpCards, CapsFaceUpIfFaceUpNotAll) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, + {} + }; + + game_state gs(sr, piles); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_DOWN(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, IgnoreCapsIfFaceUpAll) { + sol_rules sr; + sr.tableau_pile_count = 3; + sr.built_group_pol = pol::SAME_SUIT; + sr.build_pol = pol::SAME_SUIT; + sr.move_built_group = true; + sr.face_up = fu::ALL; + + initializer_list<pile> piles = { + {"3S"}, + {"2s","AS"}, + {} + }; + + game_state gs(sr, piles); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, MoveTurnsFaceUp) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::regular, 1, 2)); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[2][0]); +} + +TEST(FaceUpCards, BuiltGroupMoveTurnsFaceUp) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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"}, + {"3s","2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::built_group, 1, 2, 2)); + + 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]); +} + +TEST(FaceUpCards, MoveAlreadyFaceUpNoChange) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + gs.make_move(move(mt::regular, 1, 2)); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[2][0]); +} + +TEST(FaceUpCards, FaceDownNoBuiltGroup) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"3S"}, + {"2s","AS"}, + {} + }, + { + // Regular moves + move(move::mtype::regular, 0, 2, 1), + move(move::mtype::regular, 1, 2, 1), + } + ); +} + +TEST(FaceUpCards, FaceUpBuiltGroup) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"3S"}, + {"2S","AS"}, + {} + }, + { + // Regular moves + move(mt::regular, 0, 2, 1), + move(mt::regular, 1, 2, 1), + + // Built group moves + move(mt::built_group, 1, 0, 2), + move(mt::built_group, 1, 2, 2) + } + ); +} + +TEST(FaceUpCards, FaceUpBuiltGroup2Not3) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, + {} + }; + + test_helper::expected_moves_test( + sr, + { + {"4S"}, + {"3s","2S","AS"}, + {} + }, + { + // Regular moves + move(mt::regular, 0, 2, 1), + move(mt::regular, 1, 2, 1), + + // Built group moves + move(mt::built_group, 1, 2, 2) + } + ); +} + +TEST(FaceUpCards, UndoTurnsBackFaceDown) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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 = { + {"3S"}, + {"2s","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + move m = move(mt::regular, 1, 2); + gs.make_move(m); + gs.undo_move(m); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_DOWN(gs.get_data()[1][1]); +} + +TEST(FaceUpCards, UndoBuiltGroupTurnsBackFaceDown) { + sol_rules sr; + sr.tableau_pile_count = 3; + 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"}, + {"3s","2S","AS"}, // from + {} // to + }; + + game_state gs(sr, piles); + move m = move(mt::built_group, 1, 2, 2); + gs.make_move(m); + gs.undo_move(m); + + ASSERT_FACE_UP(gs.get_data()[0][0]); + ASSERT_FACE_UP(gs.get_data()[1][0]); + ASSERT_FACE_UP(gs.get_data()[1][1]); + ASSERT_FACE_DOWN(gs.get_data()[1][2]); +} |
