diff options
| author | Tom Harley | 2019-01-27 15:37:06 +0000 |
|---|---|---|
| committer | Tom Harley | 2019-01-27 15:37:06 +0000 |
| commit | a996283af7c21baaff0e114d58c34db820902c6f (patch) | |
| tree | 2fe5b6f7a800d4a7b8a65ee345f8c98aa138e36b /solvitaire/src/test/integration_tests/canfield_test.cpp | |
| parent | Split code into 3 files (diff) | |
| download | metasol-a996283af7c21baaff0e114d58c34db820902c6f.tar.gz metasol-a996283af7c21baaff0e114d58c34db820902c6f.zip | |
Reorganise repo
All solvitaire content has been shoved into a subdirectory to tidy up the root of the project. This also means solvitaire is treated similarly to other dependencies of the project, and allows other dependencies to be added easily.
There’s also a lot of other work done here, such as usign a thread pool library to manage the running of the voters.
Diffstat (limited to 'solvitaire/src/test/integration_tests/canfield_test.cpp')
| -rw-r--r-- | solvitaire/src/test/integration_tests/canfield_test.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/solvitaire/src/test/integration_tests/canfield_test.cpp b/solvitaire/src/test/integration_tests/canfield_test.cpp new file mode 100644 index 0000000..0cb14b2 --- /dev/null +++ b/solvitaire/src/test/integration_tests/canfield_test.cpp @@ -0,0 +1,139 @@ +// +// Created by thecharlesblake on 10/4/17. +// + +#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"; + +TEST(Canfield, SimpleSolvable) { + EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type)); +} + +TEST(Canfield, ComplexSolvable) { + EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type)); +} + +TEST(Canfield, SimpleUnsolvable) { + EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type)); +} + +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{ + {"AC"},{},{},{}, // Foundations + {},{}, // Stock-waste + {}, // Reserve + {"2C","AH"},{"3H"},{"3C","2D"} // Tableau piles + }); + + vector<move> actual_moves = gs.get_legal_moves(); + vector<move> exp_moves = { + move(move::mtype::built_group, 7, 8, 2), + move(move::mtype::regular, 7, 1, 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; +} |
