diff options
Diffstat (limited to 'solvitaire/src/test/unit_tests')
| m--------- | solvitaire | 0 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/built_group_move_gen_test.cpp | 313 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/card_test.cpp | 92 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/deal_parser_test.cpp | 143 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/face_up_cards_test.cpp | 317 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/foundations_dominance_test.cpp | 29 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/global_cache_test.cpp | 78 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/k_plus_stock_test.cpp | 426 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/legal_move_gen_test.cpp | 326 | ||||
| -rw-r--r-- | solvitaire/src/test/unit_tests/pile_test.cpp | 87 |
10 files changed, 0 insertions, 1811 deletions
diff --git a/solvitaire b/solvitaire new file mode 160000 +Subproject b835e10bfb21a73b4f89e09ddeb400f41538483 diff --git a/solvitaire/src/test/unit_tests/built_group_move_gen_test.cpp b/solvitaire/src/test/unit_tests/built_group_move_gen_test.cpp deleted file mode 100644 index 5e3a492..0000000 --- a/solvitaire/src/test/unit_tests/built_group_move_gen_test.cpp +++ /dev/null @@ -1,313 +0,0 @@ -// -// 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::spaces_policy s_pol; -typedef sol_rules::built_group_type bgt; - -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 = bgt::YES; - - test_helper::expected_moves_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 = bgt::YES; - - test_helper::expected_moves_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 = bgt::YES; - - test_helper::expected_moves_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 = bgt::NO; - - test_helper::expected_moves_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 = 6; - sr.build_pol = pol::SAME_SUIT; - sr.built_group_pol = pol::SAME_SUIT; - sr.move_built_group = bgt::YES; - - test_helper::expected_moves_test( - sr, - { - {"4C"}, - {"3C", "2C", "AC"}, // Same suit - {"3H", "2S", "AH"}, // Red black - {"3D", "2D", "AS"}, // Any suit - {}, - {"3C"} - }, - { - // 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, 5, 0, 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), - move(move::mtype::built_group, 1, 5, 2) - } - ); -} - -TEST(BuiltGroupMoveGen, RedBlackOccupied) { - sol_rules sr; - sr.tableau_pile_count = 6; - sr.build_pol = pol::RED_BLACK; - sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = bgt::YES; - - test_helper::expected_moves_test( - sr, - { - {"4C"}, - {"3C", "2C", "AC"}, // Same suit - {"3H", "2S", "AH"}, // Red black - {"3D", "2D", "AS"}, // Any suit - {}, - {"3C"} - }, - { - // Regular moves - 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, 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, 5, 2) - } - ); -} - -TEST(BuiltGroupMoveGen, AnySuitOccupied) { - sol_rules sr; - sr.tableau_pile_count = 6; - sr.build_pol = pol::ANY_SUIT; - sr.built_group_pol = pol::ANY_SUIT; - sr.move_built_group = bgt::YES; - - test_helper::expected_moves_test( - sr, - { - {"4C"}, - {"3C", "2C", "AC"}, // Same suit - {"3H", "2S", "AH"}, // Red black - {"3D", "2D", "AS"}, // Any suit - {}, - {"3C"} - }, - { - // 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, 5, 0, 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), - - move(move::mtype::built_group, 1, 5, 2), - move(move::mtype::built_group, 2, 5, 2), - move(move::mtype::built_group, 3, 5, 2) - } - ); -} - -TEST(BuiltGroupMoveGen, KingsOnly) { - sol_rules sr; - sr.tableau_pile_count = 5; - sr.build_pol = pol::SAME_SUIT; - sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = bgt::YES; - sr.spaces_pol = s_pol::KINGS; - - test_helper::expected_moves_test( - sr, - { - {}, - {"KC", "QC", "JC"}, // Same suit - {"KH", "QS", "JH"}, // Red black - {"KD", "QD", "JS"}, // Any suit - {} - }, - { - // Built group moves - move(move::mtype::built_group, 2, 0, 3), - move(move::mtype::built_group, 2, 4, 3) - } - ); -} - -TEST(BuiltGroupMoveGen, NoBuild) { - sol_rules sr; - sr.tableau_pile_count = 5; - sr.build_pol = pol::SAME_SUIT; - sr.built_group_pol = pol::RED_BLACK; - sr.move_built_group = bgt::YES; - sr.spaces_pol = s_pol::NO_BUILD; - - test_helper::expected_moves_test( - sr, - { - {}, - {"KC", "QC", "JC"}, // Same suit - {"KH", "QS", "JH"}, // Red black - {"KD", "QD", "JS"}, // Any suit - {} - }, - {} - ); -} diff --git a/solvitaire/src/test/unit_tests/card_test.cpp b/solvitaire/src/test/unit_tests/card_test.cpp deleted file mode 100644 index 346dff9..0000000 --- a/solvitaire/src/test/unit_tests/card_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// -// Created by thecharlesblake on 1/11/18. -// - -#include <gtest/gtest.h> - -#include "../test_helper.h" -#include "../../main/game/card.h" - -TEST(Card, Rank) { - for (card::rank_t r = 1; r <= 13; r++) { - card::suit_t s = card::suit::Clubs; - card c(s, r); - ASSERT_EQ(r, c.get_rank()); - } -} - -TEST(Card, Suit) { - for (card::suit_t s : { - card::suit::Clubs, - card::suit::Hearts, - card::suit::Spades, - card::suit::Diamonds - }) { - card::rank_t r = 1; - card c(s, r); - ASSERT_EQ(s, c.get_suit()); - } -} - -TEST(Card, Colour) { - card::rank_t r = 1; - - for (card::suit_t s : { - card::suit::Clubs, - card::suit::Spades - }) { - card c(s, r); - ASSERT_EQ(card::colour::Black, c.get_colour()); - } - - for (card::suit_t s : { - card::suit::Hearts, - card::suit::Diamonds - }) { - card c(s, r); - ASSERT_EQ(card::colour::Red, c.get_colour()); - } -} - -TEST(Card, EqOps) { - for (card::rank_t r = 1; r <= 13; r++) { - for (card::suit_t s : { - card::suit::Clubs, - card::suit::Hearts, - card::suit::Spades, - card::suit::Diamonds - }) { - card a(s, r); - card b(s, r); - ASSERT_TRUE (a == b); - ASSERT_FALSE(a != b); - } - } -} - -TEST(Card, RelativeOps) { - for (card::rank_t r = 1; r <= 12; r++) { - for (card::suit_t s : { - card::suit::Clubs, - card::suit::Hearts, - card::suit::Spades, - card::suit::Diamonds - }) { - card a(s, r); - card b(s, card::rank_t(r+1)); - ASSERT_TRUE (a < b); - ASSERT_TRUE (a <= b); - ASSERT_FALSE(a > b); - ASSERT_FALSE(a >= b); - } - } -} - -TEST(Card, StringConstructor) { - ASSERT_EQ(card(card::suit::Spades , card::rank_t(1) ), card("AS" )); - ASSERT_EQ(card(card::suit::Clubs , card::rank_t(1) ), card("Ac" )); - ASSERT_EQ(card(card::suit::Diamonds, card::rank_t(5) ), card("5D" )); - ASSERT_EQ(card(card::suit::Hearts , card::rank_t(11)), card("11H")); - ASSERT_EQ(card(card::suit::Spades , card::rank_t(11)), card("JS" )); - ASSERT_EQ(card(card::suit::Clubs , card::rank_t(13)), card("kc" )); -} diff --git a/solvitaire/src/test/unit_tests/deal_parser_test.cpp b/solvitaire/src/test/unit_tests/deal_parser_test.cpp deleted file mode 100644 index db2bd31..0000000 --- a/solvitaire/src/test/unit_tests/deal_parser_test.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// -// Created by thecharlesblake on 1/11/18. -// - -#include <gtest/gtest.h> - -#include "../../../lib/rapidjson/stringbuffer.h" -#include "../../../lib/rapidjson/document.h" - -#include "../../main/input-output/input/json-parsing/deal_parser.h" -#include "../../main/input-output/input/json-parsing/json_helper.h" - -using namespace std; -using namespace rapidjson; - -void run_deal_parser_test(bool, const char*); - -TEST(DealParser, SimpleTableauLetter) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["AS"] - ] -} -)"); -} - -TEST(DealParser, SimpleTableauNumber) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["1S"] - ] -} -)"); -} - -TEST(DealParser, IllegalTableauNumber) { - run_deal_parser_test(false, R"( -{ - "tableau piles": [ - ["14S"] - ] -} -)"); -} - -TEST(DealParser, IllegalTableauSuit) { - run_deal_parser_test(false, R"( -{ - "tableau piles": [ - ["14A"] - ] -} -)"); -} - -TEST(DealParser, SimpleTableauCase) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["kc"] - ] -} -)"); -} - -TEST(DealParser, AdvancedTableau) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["5S","13C","4C","3C","2S","2c"], - ["5D","qD","3S","1d","2D"], - ["5H","4S","JH","3h","2H"] - ] -} -)"); -} - -TEST(DealParser, Hole) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["5S","13C","4C"] - ], - "hole": "qD" -} -)"); -} - -TEST(DealParser, Stock) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["5S","13C","4C"] - ], - "stock": ["1S","JC","7H"] -} -)"); -} - -TEST(DealParser, Waste) { - run_deal_parser_test(true, R"( -{ - "tableau piles": [ - ["5S","13C","4C"] - ], - "waste": ["1S","JC","7H"] -} -)"); -} - -TEST(DealParser, IllegalPileType) { - run_deal_parser_test(false, R"( -{ - "tableau piles": [ - ["5S","13C","4C"] - ], - "other": ["1S","JC","7H"] -} -)"); -} - -void run_deal_parser_test(bool validity, const char* json) { - Document in_doc; - in_doc.Parse(json); - if (in_doc.HasParseError()) { - throw runtime_error("invalid json"); - } - - Document val_doc; - val_doc.Parse(deal_parser::deal_schema_json().c_str()); - SchemaDocument sd(val_doc); - SchemaValidator validator(sd); - bool acc = in_doc.Accept(validator); - if (acc) { - ASSERT_TRUE(validity == acc) << "JSON accepted when it should not have " - "been:\n" << json; - } else { - ASSERT_TRUE(validity == acc) << json_helper::schema_err_str(validator) - << "\n" << json; - } -} diff --git a/solvitaire/src/test/unit_tests/face_up_cards_test.cpp b/solvitaire/src/test/unit_tests/face_up_cards_test.cpp deleted file mode 100644 index 1311958..0000000 --- a/solvitaire/src/test/unit_tests/face_up_cards_test.cpp +++ /dev/null @@ -1,317 +0,0 @@ -// -// 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" -#include "../../main/game/global_cache.h" - -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; - -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) { - 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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il 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 = bgt::YES; - sr.face_up = fu::ALL; - - string_il 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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il piles = { - {"4S"}, - {"3s","AS"}, // from - {"2S"} // to - }; - - test_helper::expected_moves_test( - sr, - piles, - { - // Regular moves - move(move::mtype::regular, 1, 2, 1, true) - } - ); - - game_state gs(sr, piles); - 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]); - ASSERT_FACE_UP(gs.get_data()[2][0]); -} - -TEST(FaceUpCards, BuiltGroupMoveTurnsFaceUp) { - sol_rules sr; - sr.tableau_pile_count = 2; - sr.built_group_pol = pol::SAME_SUIT; - sr.build_pol = pol::SAME_SUIT; - sr.move_built_group = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - 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, 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()[1][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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il piles = { - {"4S"}, - {"3s","AS"}, // from - {"2S"} // to - }; - - test_helper::expected_moves_test( - sr, - piles, - { - // Regular moves - move(move::mtype::regular, 1, 2, 1, true) - } - ); - - game_state gs(sr, piles); - 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]); - 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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - test_helper::expected_moves_test( - sr, - { - {"4S"}, - {"3s","AS"}, - {"2S"} - }, - { - // Regular moves - move(move::mtype::regular, 1, 2, 1, true) - } - ); -} - -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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - test_helper::expected_moves_test( - sr, - { - {"3S"}, - {"2S","AS"}, - {} - }, - { - // Regular moves - 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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - test_helper::expected_moves_test( - sr, - { - {"4S"}, - {"3s","2S","AS"}, - {"3S"} - }, - { - // Regular moves - move(mt::regular, 2, 0, 1, false), - - // Built group moves - move(mt::built_group, 1, 2, 2, true) - } - ); -} - -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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il piles = { - {"3S"}, - {"2s","AS"}, // from - {} // to - }; - - game_state gs(sr, piles); - move m = move(mt::regular, 1, 2, 1, true); - 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 = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il piles = { - {"4S"}, - {"3s","2S","AS"}, // from - {} // to - }; - - game_state gs(sr, piles); - move m = move(mt::built_group, 1, 2, 2, true); - 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]); -} - -TEST(FaceUpCards, CacheEncodesFaceDown) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.built_group_pol = pol::RED_BLACK; - sr.build_pol = pol::RED_BLACK; - sr.move_built_group = bgt::YES; - sr.face_up = fu::TOP_CARDS; - - string_il piles = { - {"2C"}, - {"2s","AH"}, - {} - }; - - game_state gs(sr, piles); - lru_cache cache(gs, 1000); - bool new_state; - - 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, 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, 1, false)); - new_state = cache.insert(gs).second; - ASSERT_TRUE(new_state) << "AH to 2C"; - - 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/solvitaire/src/test/unit_tests/foundations_dominance_test.cpp b/solvitaire/src/test/unit_tests/foundations_dominance_test.cpp deleted file mode 100644 index 8fdc285..0000000 --- a/solvitaire/src/test/unit_tests/foundations_dominance_test.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// 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/global_cache.h" - -typedef sol_rules::build_policy pol; - -TEST(FoundationsDominance, SameSuit) { - test_helper::run_foundations_dominance_test(pol::SAME_SUIT, { - "AC","2C","3C","4C","AH","2H","3H","4H","AS","2S","3S","4S","AD", - "2D","3D","4D"}); -} - -TEST(FoundationsDominance, RedBlack) { - test_helper::run_foundations_dominance_test(pol::RED_BLACK, { - "AC","2C","AH","2H","AS","3H","2S","AD","3C","4H","3S","2D","4C", - "4S","3D","4D"}); -} - -TEST(FoundationsDominance, AnySuit) { - test_helper::run_foundations_dominance_test(pol::ANY_SUIT, { - "AC","2C","AH","2H","AS","2S","AD","3C","3H","3S","2D","4C","4H", - "4S","3D","4D"}); -}
\ No newline at end of file diff --git a/solvitaire/src/test/unit_tests/global_cache_test.cpp b/solvitaire/src/test/unit_tests/global_cache_test.cpp deleted file mode 100644 index 93ef105..0000000 --- a/solvitaire/src/test/unit_tests/global_cache_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// -// 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/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, string_il{{},{},{}}); - lru_cache cache(gs, 1000); - - 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, {{"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, {{"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, string_il{{},{},{}}); - lru_cache cache(gs, 1000); - - 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, {{"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, {{"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, string_il{{},{},{}}); - lru_cache cache(gs, 1000); - - 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, {{"4C"},{"5D"},{}})); - ASSERT_TRUE (cache.contains(game_state(rules, {{},{"4C"},{"5D"}}))); - ASSERT_FALSE(cache.contains(game_state(rules, {{},{"4C"},{}}))); -} diff --git a/solvitaire/src/test/unit_tests/k_plus_stock_test.cpp b/solvitaire/src/test/unit_tests/k_plus_stock_test.cpp deleted file mode 100644 index dcd4410..0000000 --- a/solvitaire/src/test/unit_tests/k_plus_stock_test.cpp +++ /dev/null @@ -1,426 +0,0 @@ -// -// 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::stock_deal_type sdt; - -using std::vector; -using std::ostream; -using std::initializer_list; - - -TEST(KPlusStock, NoRedealExact) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = false; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2D","3S","AD","2S","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3), - move(move::mtype::stock_k_plus, 0, 3, 9), - }, - move(move::mtype::stock_k_plus, 0, 3, 9), - 0, 8, - card(), "2D" - ); -} - -TEST(KPlusStock, NoRedealOneExtra) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = false; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","AD","2S","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3), - move(move::mtype::stock_k_plus, 0, 3, 7), - }, - move(move::mtype::stock_k_plus, 0, 3, 7), - 0, 6, - card(), "AD" - ); -} - -TEST(KPlusStock, NoRedealTwoExtra) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = false; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2S","2H","AD","2D","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3) - }, - move(move::mtype::stock_k_plus, 0, 4, 3), - 5, 2, - "3C", "AH" - ); -} - -TEST(KPlusStock, RedealExact) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2D","3S","AD","2S","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3, false, false), - move(move::mtype::stock_k_plus, 0, 3, 9, false, true), - }, - move(move::mtype::stock_k_plus, 0, 3, 9, false, true), - 8, 0, - "AS", card() - ); -} - -TEST(KPlusStock, RedealOneExtra) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","AD","2S","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3, false, false), - move(move::mtype::stock_k_plus, 0, 3, 7, false, true), - }, - move(move::mtype::stock_k_plus, 0, 3, 7, false, true), - 6, 0, - "AS", card() - ); -} - -TEST(KPlusStock, RedealTwoExtra) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2S","2H","AD","2D","3C","AC","AH","AS"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 4, 3, false, false) - }, - move(move::mtype::stock_k_plus, 0, 4, 3, false, false), - 5, 2, - "3C", "AH" - ); -} - -TEST(KPlusStock, RedealKPlus3Waste) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2D","3S","AD","2S","3C"}, - {"AS","AH","AC"}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 3, 6, false, true), - move(move::mtype::stock_k_plus, 0, 4, 0, false, false) - }, - move(move::mtype::stock_k_plus, 0, 3, 6, false, true), - 8, 0, - "AS", card() - ); -} - -TEST(KPlusStock, RedealKPlus4Waste) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","AD","3S","2D","2S"}, - {"AS","AH","AC","3C"}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 3, 5, false, true), - move(move::mtype::stock_k_plus, 0, 4, -1, false, false), - move(move::mtype::stock_k_plus, 0, 2, 2, false, false) - }, - move(move::mtype::stock_k_plus, 0, 2, 2, false, false), - 3, 5, - "3S", "2S" - ); -} - -TEST(KPlusStock, RedealKPlus5Waste) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 10; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2S","2D","2H","AD","2S"}, - {"AS","AH","AC","3C","4S"}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 3, 3, false, false), - move(move::mtype::stock_k_plus, 0, 4, -2, false, false), - move(move::mtype::stock_k_plus, 0, 2, 4, false, false) - }, - move(move::mtype::stock_k_plus, 0, 3, 3, false, false), - 2, 7, - "2D", "AD" - ); -} - -TEST(KPlusStock, RedealKPlusEmptyStock) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2D","3S","AD","2S","3C"}, - {"AS","AH","AC"}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 3, 6, false, true), - move(move::mtype::stock_k_plus, 0, 4, 0, false, false) - }, - move(move::mtype::stock_k_plus, 0, 3, 6, false, true), - 8, 0, - "AS", card() - ); -} - -TEST(KPlusStock, NoRedealCellFoundationMoves) { - sol_rules sr; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = false; - sr.stock_deal_count = 3; - sr.cells = 2; - sr.foundations_present = true; - - test_helper::k_plus_stock_test( - sr, - { - {"AC"}, {}, {}, {}, - {"2D"}, {}, - {"2H","AS","2C","AH","2S","3C"}, - {"3S"} - }, - { - // Cell moves - move(move::mtype::stock_k_plus, 6, 5, 3), - move(move::mtype::stock_k_plus, 6, 5, 6), - - // Foundation moves - move(move::mtype::stock_k_plus, 6, 1, 3), - - // Regular waste move - move(move::mtype::stock_k_plus, 6, 5, 0) - }, - move(move::mtype::stock_k_plus, 6, 1, 3), - 3, 3, - "2C", "2S" - ); -} - -TEST(KPlusStock, RedealCellFoundationMoves) { - sol_rules sr; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 3; - sr.cells = 2; - sr.foundations_present = true; - - test_helper::k_plus_stock_test( - sr, - { - {"AC"}, {}, {}, {}, - {"2D"}, {}, - {"2H","AS","2C","AH","2S","3C"}, - {"3S"} - }, - { - // Cell moves - move(move::mtype::stock_k_plus, 6, 5, 3, false, false), - move(move::mtype::stock_k_plus, 6, 5, 6, false, true), - move(move::mtype::stock_k_plus, 6, 5, 2, false, false), - move(move::mtype::stock_k_plus, 6, 5, 5, false, false), - - // Foundation moves - move(move::mtype::stock_k_plus, 6, 1, 3, false, false), - move(move::mtype::stock_k_plus, 6, 2, 5, false, false), - - // Regular waste move - move(move::mtype::stock_k_plus, 6, 5, 0) - }, - move(move::mtype::stock_k_plus, 6, 2, 5, false, false), - 1, 5, - "2H", "2C" - ); -} - -TEST(KPlusStock, RedealCount1BottomStock) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 1; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2S","AD","2D"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 2, 1, false, false), - move(move::mtype::stock_k_plus, 0, 3, 4, false, true) - }, - move(move::mtype::stock_k_plus, 0, 3, 4, false, true), - 3, 0, - "2D", card() - ); -} - -TEST(KPlusStock, RedealCount1TopStock) { - sol_rules sr; - sr.tableau_pile_count = 3; - sr.build_pol = pol::SAME_SUIT; - sr.stock_size = 9; - sr.stock_deal_t = sdt::WASTE; - sr.stock_redeal = true; - sr.stock_deal_count = 1; - - test_helper::k_plus_stock_test( - sr, - { - {"2H","2S","AD","2D"}, - {}, - {"3D"}, - {"3H"}, - {"2C"} - }, - { - move(move::mtype::stock_k_plus, 0, 2, 1, false, false), - move(move::mtype::stock_k_plus, 0, 3, 4, false, true) - }, - move(move::mtype::stock_k_plus, 0, 2, 1, false, false), - 3, 0, - "AD", card() - ); -} diff --git a/solvitaire/src/test/unit_tests/legal_move_gen_test.cpp b/solvitaire/src/test/unit_tests/legal_move_gen_test.cpp deleted file mode 100644 index da5c63c..0000000 --- a/solvitaire/src/test/unit_tests/legal_move_gen_test.cpp +++ /dev/null @@ -1,326 +0,0 @@ -// -// 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" -#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 sol_rules::built_group_type bgt; - -using std::vector; -using std::ostream; - -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, string_il{ - {"2C"}, - {"2H"}, - {"2D"}, - {"2S"}, - {"AC"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - 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(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, BuildPolRedBlack) { - sol_rules sr; - sr.build_pol = pol::RED_BLACK; - sr.tableau_pile_count = 5; - - game_state gs(sr, string_il{ - {"2C"}, - {"2H"}, - {"2S"}, - {"2D"}, - {"AC"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 4,1), - move(move::mtype::regular, 4,3) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, BuildPolSameSuit) { - sol_rules sr; - sr.build_pol = pol::SAME_SUIT; - sr.tableau_pile_count = 5; - - game_state gs(sr, string_il{ - {"2C"}, - {"2H"}, - {"2S"}, - {"2D"}, - {"AC"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 4,0) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, BuildPolNoBuild) { - sol_rules sr; - sr.build_pol = pol::NO_BUILD; - sr.tableau_pile_count = 5; - - game_state gs(sr, string_il{ - {"2C"}, - {"2H"}, - {"2S"}, - {"2D"}, - {"AC"} - }); - 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(LegalMoveGen, SpacesPolAny) { - sol_rules sr; - sr.spaces_pol = s_pol::ANY; - sr.tableau_pile_count = 2; - - game_state gs(sr, string_il{ - {}, - {"AC"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - // move(move::mtype::regular, 1, 0) // Now forbidden as always pointless - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, SpacesPolKings) { - sol_rules sr; - sr.spaces_pol = s_pol::KINGS; - sr.tableau_pile_count = 3; - - game_state gs(sr, string_il{ - {}, - {"AC"}, - {"3S","KD"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 2, 0) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, SpacesPolNoBuild) { - sol_rules sr; - sr.spaces_pol = s_pol::NO_BUILD; - sr.tableau_pile_count = 2; - - game_state gs(sr, string_il{ - {}, - {"AC"} - }); - 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(LegalMoveGen, MoveBuiltGroupTrue) { - sol_rules sr; - sr.move_built_group = bgt::YES; - sr.tableau_pile_count = 2; - - game_state gs(sr, string_il{ - {}, - {"2C", "AC"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 1, 0, 1), - move(move::mtype::built_group, 1, 0, 2) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, MoveBuiltGroupFalse) { - sol_rules sr; - sr.move_built_group = bgt::NO; - sr.tableau_pile_count = 2; - - game_state gs(sr, string_il{ - {}, - {"AC", "2C"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 1, 0, 1) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, Foundations) { - sol_rules sr; - sr.foundations_present = true; - sr.tableau_pile_count = 4; - - game_state gs(sr, string_il{ - {}, {}, {}, {}, - {"AC"}, - {"AH"}, - {"AS"}, - {"AD"}, - }); - vector<move> actual_moves = gs.get_legal_moves(); - - 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(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, FoundationsRemovable) { - sol_rules sr; - sr.foundations_present = true; - sr.foundations_removable = true; - sr.tableau_pile_count = 1; - - game_state gs(sr, string_il{ - {"AC","2C","3C"}, // Without a few cards here dominance logic blocks - {}, // removing from foundation - {}, - {}, - {} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 0, 4) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - - -TEST(LegalMoveGen, TwoDecksFoundations) { - sol_rules sr; - sr.two_decks = true; - sr.foundations_removable = true; - sr.foundations_present = true; - sr.tableau_pile_count = 4; - - game_state gs(sr, string_il{ - {"AC"}, {}, {}, {}, {}, {}, {"AS"}, {}, - {}, - {"AH"}, - {}, - {"AD"}, - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - // Aces up - move(move::mtype::regular, 9, 1), - move(move::mtype::regular, 9, 5), - move(move::mtype::regular, 11, 3), - move(move::mtype::regular, 11, 7), - - // Aces down - move(move::mtype::regular, 0, 8), - move(move::mtype::regular, 0, 10), - move(move::mtype::regular, 6, 8), - move(move::mtype::regular, 6, 10), - - // Aces across (forbidden now) - //move(move::mtype::regular, 9, 8), - //move(move::mtype::regular, 9, 10), - //move(move::mtype::regular, 11, 8), - //move(move::mtype::regular, 11, 10), - - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, Cells) { - sol_rules sr; - sr.cells = 2; - sr.tableau_pile_count = 1; - - game_state gs(sr, string_il{ - {"3D"}, {}, // The cells - {"4H"} - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::regular, 0, 2), - move(move::mtype::regular, 2, 1) - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} - -TEST(LegalMoveGen, StockDealToTableau) { - sol_rules sr; - sr.foundations_present = true; - sr.tableau_pile_count = 3; - sr.stock_size = 2; - sr.stock_deal_t = sdt::TABLEAU_PILES; - - game_state gs(sr, string_il{ - {}, {}, {}, {}, // The foundations - {"AC", "AD"}, // The stock - {"3H"}, {"5D"}, {"7C"} // The tableau piles - }); - vector<move> actual_moves = gs.get_legal_moves(); - - vector<move> exp_moves = { - move(move::mtype::stock_to_all_tableau, 0, 0, 2) // Special stock-to-tableau syntax - }; - - ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; -} diff --git a/solvitaire/src/test/unit_tests/pile_test.cpp b/solvitaire/src/test/unit_tests/pile_test.cpp deleted file mode 100644 index a5aeb66..0000000 --- a/solvitaire/src/test/unit_tests/pile_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -// Created by thecharlesblake on 1/11/18. -// - -#include <gtest/gtest.h> - -#include "../test_helper.h" -#include "../../main/game/pile.h" - -TEST(Pile, Size) { - pile p = {}; - ASSERT_EQ(0, p.size()); - - p = {"AS"}; - ASSERT_EQ(1, p.size()); - - p = {"AS", "KC", "4H"}; - ASSERT_EQ(3, p.size()); -} - -TEST(Pile, TopCard) { - pile p = {"AS"}; - ASSERT_EQ(card("AS"), p.top_card()); - - p = {"AS", "KC", "4H"}; - ASSERT_NE(card("AS"), p.top_card()); - ASSERT_EQ(card("4H"), p.top_card()); -} - -TEST(Pile, Index) { - pile p = {"AS"}; - ASSERT_EQ(card("AS"), p[0]); - - p = {"AS", "KC", "4H"}; - ASSERT_EQ(card("AS"), p[2]); - ASSERT_EQ(card("KC"), p[1]); - ASSERT_EQ(card("4H"), p[0]); -} - -TEST(Pile, Place) { - pile t1 = {}; - pile t2 = {"AS"}; - pile t3 = {"AS", "KC", "4H"}; - - pile p = {}; - ASSERT_EQ(p, t1); - - p.place("AS"); - ASSERT_NE(p, t1); - ASSERT_EQ(p, t2); - - p.place("KC"); - p.place("4H"); - ASSERT_NE(p, t2); - ASSERT_EQ(p, t3); -} - -TEST(Pile, Take) { - pile t1 = {}; - pile t2 = {"AS"}; - pile t3 = {"AS", "KC", "4H"}; - - pile p = {"AS", "KC", "4H"}; - ASSERT_EQ(p, t3); - - p.take(); - p.take(); - ASSERT_NE(p, t3); - ASSERT_EQ(p, t2); - - p.take(); - ASSERT_NE(p, t2); - ASSERT_EQ(p, t1); -} - -TEST(Pile, CompOperators) { - pile p1 = {"3S"}; - pile p2 = {"AS", "AD", "AC"}; - pile p3 = {"2S", "2D", "2C"}; - pile p4 = {"AS", "AD", "AC", "AH"}; - - ASSERT_LT(p1, p2); - ASSERT_LT(p2, p3); - ASSERT_LT(p3, p4); - ASSERT_LT(p1, p4); - ASSERT_EQ(p4, p4); -} |
