From 12e8d1f342303394f8e6be72c08a92e3a4097bfb Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 15:45:14 +0100 Subject: Add Canfield unit tests --- src/test/integration_tests/canfield_test.cpp | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'src/test/integration_tests/canfield_test.cpp') diff --git a/src/test/integration_tests/canfield_test.cpp b/src/test/integration_tests/canfield_test.cpp index 6a045ea..406b23a 100644 --- a/src/test/integration_tests/canfield_test.cpp +++ b/src/test/integration_tests/canfield_test.cpp @@ -5,8 +5,14 @@ #include #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> string_il; const static std::string path = "resources/canfield/"; const static std::string type = "simple-canfield"; @@ -26,3 +32,99 @@ 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 actual_moves = gs.get_legal_moves(); + vector 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 + {"2H","3S","AH"},{"AC"},{"2D"} // Tableau piles + }); + + vector actual_moves = gs.get_legal_moves(); + vector exp_moves = { + move(move::mtype::built_group, 7, 8, 3) + }; + + 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 actual_moves = gs.get_legal_moves(); + vector 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{ + {"3C"},{},{},{}, // Foundations + {"3D"},{"2D"}, // Stock-waste + {"3H"}, // Reserve + {"2H","3S","AH"},{},{"AC"} // Tableau piles + }); + + vector actual_moves = gs.get_legal_moves(); + vector exp_moves = { + move(move::mtype::regular, 6, 8, 1) + }; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; +} + +TEST(Canfield, AutoReserveThenWaste) { + sol_rules sr = rules_parser::from_preset("simple-canfield"); + + game_state gs(sr, string_il{ + {"3C"},{},{},{}, // Foundations + {"3D"},{"3H"}, // Stock-waste + {}, // Reserve + {"2H","3S","AH"},{},{"AC"} // Tableau piles + }); + + vector actual_moves = gs.get_legal_moves(); + vector exp_moves = { + move(move::mtype::stock_k_plus, 4, 8, 1), + move(move::mtype::stock_k_plus, 4, 8, 2), + }; + + ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; +} -- cgit v1.2.1 From 357fab143bcb41d55fb9060bcfbf257a8586e03c Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Mon, 23 Jul 2018 12:54:47 +0100 Subject: Small bug fixes inc found. base card & whole piles --- src/test/integration_tests/canfield_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/test/integration_tests/canfield_test.cpp') diff --git a/src/test/integration_tests/canfield_test.cpp b/src/test/integration_tests/canfield_test.cpp index 406b23a..cdb6d98 100644 --- a/src/test/integration_tests/canfield_test.cpp +++ b/src/test/integration_tests/canfield_test.cpp @@ -65,12 +65,13 @@ TEST(Canfield, MoveWholePile) { {"3C"},{},{},{}, // Foundations {},{}, // Stock-waste {}, // Reserve - {"2H","3S","AH"},{"AC"},{"2D"} // Tableau piles + {"3H","2S","AH"},{"AS"},{"2D"} // Tableau piles }); vector actual_moves = gs.get_legal_moves(); vector exp_moves = { - move(move::mtype::built_group, 7, 8, 3) + 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; -- cgit v1.2.1 From 2acab3e51cabd8ba80738b1faf791980d2abf724 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Tue, 24 Jul 2018 12:00:04 +0100 Subject: Fix canfield to pass all unit tests --- src/test/integration_tests/canfield_test.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/test/integration_tests/canfield_test.cpp') diff --git a/src/test/integration_tests/canfield_test.cpp b/src/test/integration_tests/canfield_test.cpp index cdb6d98..006f4fb 100644 --- a/src/test/integration_tests/canfield_test.cpp +++ b/src/test/integration_tests/canfield_test.cpp @@ -97,18 +97,21 @@ TEST(Canfield, AutoReserve) { sol_rules sr = rules_parser::from_preset("simple-canfield"); game_state gs(sr, string_il{ - {"3C"},{},{},{}, // Foundations - {"3D"},{"2D"}, // Stock-waste + {"2C"},{},{},{}, // Foundations + {"3D","2D"},{}, // Stock-waste {"3H"}, // Reserve {"2H","3S","AH"},{},{"AC"} // Tableau piles }); vector actual_moves = gs.get_legal_moves(); - vector exp_moves = { - move(move::mtype::regular, 6, 8, 1) - }; + vector exp_moves = {}; ASSERT_TRUE(test_helper::moves_eq(exp_moves, actual_moves)) << actual_moves; + + boost::optional actual_dom_move = gs.get_dominance_move(); + boost::optional exp_dom_move = move(move::mtype::dominance, 6, 8, 1); + + ASSERT_EQ(exp_dom_move, actual_dom_move) << *actual_dom_move; } TEST(Canfield, AutoReserveThenWaste) { @@ -116,16 +119,21 @@ TEST(Canfield, AutoReserveThenWaste) { game_state gs(sr, string_il{ {"3C"},{},{},{}, // Foundations - {"3D"},{"3H"}, // Stock-waste + {"2D"},{"2S"}, // Stock-waste {}, // Reserve - {"2H","3S","AH"},{},{"AC"} // Tableau piles + {"2H","3S","AH"},{},{"AD"} // Tableau piles }); vector actual_moves = gs.get_legal_moves(); vector exp_moves = { - move(move::mtype::stock_k_plus, 4, 8, 1), - move(move::mtype::stock_k_plus, 4, 8, 2), + 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 actual_dom_move = gs.get_dominance_move(); + boost::optional exp_dom_move = boost::none; + + ASSERT_EQ(exp_dom_move, actual_dom_move) << *actual_dom_move; } -- cgit v1.2.1