diff options
| author | thecharlesblake | 2018-02-14 20:09:59 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-02-14 20:09:59 +0000 |
| commit | 46e31f8be960b9aa00e9bf9218cc712674e4455b (patch) | |
| tree | 8b8c7078b2be1178447d49336fa34bd66701cdc9 /src/test | |
| parent | Update CMake file (diff) | |
| download | metasol-46e31f8be960b9aa00e9bf9218cc712674e4455b.tar.gz metasol-46e31f8be960b9aa00e9bf9218cc712674e4455b.zip | |
Add multiple runs test for foundations dominance
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/foundations_dominance_test.cpp | 5 | ||||
| -rw-r--r-- | src/test/test_helper.cpp | 44 | ||||
| -rw-r--r-- | src/test/test_helper.h | 8 |
3 files changed, 57 insertions, 0 deletions
diff --git a/src/test/foundations_dominance_test.cpp b/src/test/foundations_dominance_test.cpp index b12a478..48134f5 100644 --- a/src/test/foundations_dominance_test.cpp +++ b/src/test/foundations_dominance_test.cpp @@ -27,3 +27,8 @@ TEST(FoundationsDominance, AnySuit) { "AC","2C","AH","2H","AS","2S","AD","3C","3H","3S","2D","4C","4H", "4S","3D","4D"}); } + +TEST(FoundationsDominance, NoSolutionChange) { + test_helper::optimisation_validity_test( + test_helper::optimisation::AUTO_FOUNDATION_MOVES); +}
\ No newline at end of file diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 246de38..37fc32d 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -110,3 +110,47 @@ void test_helper::run_foundations_dominance_test(sol_rules::build_policy policy, } ASSERT_TRUE(n->children.empty()); } + +void test_helper::optimisation_validity_test(optimisation op) { + for (string preset : { + "simple-alpha-star", + "simple-bakers-dozen", + "simple-black-hole", + "simple-canfield", + "simple-flower-garden", + "simple-fortunes-favor", + "simple-free-cell", + "simple-somerset", + "simple-spanish-patience", + "simple-spider" + }) { + vector<bool> solutions_op, solutions_no_op; + + switch (op) { + case optimisation::AUTO_FOUNDATION_MOVES: +#define NO_AUTO_FOUNDATIONS + solutions_no_op = run_many_games(preset); +#undef NO_AUTO_FOUNDATIONS + solutions_op = run_many_games(preset); + break; + } + + ASSERT_TRUE(solutions_op == solutions_no_op) << preset; + } +} + +std::vector<bool> test_helper::run_many_games(std::string preset) { +#ifdef NDEBUG + const int run_count = 2000; +#else + const int run_count = 5; +#endif + + vector<bool> solutions; + for (int seed = 0; seed < run_count; seed++) { + solver sol(game_state(rules_parser::from_preset(preset), seed)); + solutions.push_back(sol.run()); + } + + return solutions; +} diff --git a/src/test/test_helper.h b/src/test/test_helper.h index b0199af..24acb5f 100644 --- a/src/test/test_helper.h +++ b/src/test/test_helper.h @@ -12,11 +12,19 @@ class test_helper { public: + enum class optimisation { + AUTO_FOUNDATION_MOVES + }; + static bool is_solvable(const std::string&, const std::string&); static void run_card_cache_test(sol_rules::build_policy, bool, bool); static void run_foundations_dominance_test(sol_rules::build_policy policy, std::vector<card> cards); + + static void optimisation_validity_test(optimisation); + + static std::vector<bool> run_many_games(std::string); }; |
