aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharlie Blake2018-06-26 16:49:49 +0100
committerCharlie Blake2018-06-26 16:49:49 +0100
commitbffe6aec4f952f3428130af63ede573ab55e6548 (patch)
treec2bf81a02b8bdd7086165814099a4eb4af94fd92 /src
parentAdd klondike unit tests (diff)
downloadmetasol-bffe6aec4f952f3428130af63ede573ab55e6548.tar.gz
metasol-bffe6aec4f952f3428130af63ede573ab55e6548.zip

Add kplus unit tests

Diffstat (limited to 'src')
-rw-r--r--src/test/test_helper.cpp37
-rw-r--r--src/test/test_helper.h13
-rw-r--r--src/test/unit_tests/k-plus-stock-test.cpp297
3 files changed, 346 insertions, 1 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index 1bc1f24..b6584ed 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -86,6 +86,43 @@ bool test_helper::moves_eq(vector<move>& exp_moves, vector<move>& actual_moves)
return true;
}
+
+void test_helper::k_plus_stock_test
+ ( sol_rules sr
+ , string_il piles
+ , vector<move> exp_moves
+ , move m
+ , pile::size_type stock_size
+ , pile::size_type waste_size
+ , card top_stock
+ , card top_waste
+ ) {
+
+ game_state gs(sr, piles);
+ vector<move> actual_moves = gs.get_legal_moves();
+
+ ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+
+ gs.make_move(m);
+
+ ASSERT_EQ(gs.get_data()[0].size (), stock_size) << gs.get_data()[0].size ();
+ ASSERT_EQ(gs.get_data()[1].size (), waste_size) << gs.get_data()[1].size ();
+
+ if (top_stock == card())
+ ASSERT_TRUE(gs.get_data()[0].empty());
+ else
+ ASSERT_EQ(gs.get_data()[0].top_card(), top_stock ) << gs.get_data()[0].top_card().to_string();
+
+ if (top_waste == card())
+ ASSERT_TRUE(gs.get_data()[1].empty());
+ else
+ ASSERT_EQ(gs.get_data()[1].top_card(), top_waste ) << gs.get_data()[1].top_card().to_string();
+
+ gs.undo_move(m);
+
+ ASSERT_EQ(gs.get_data(), game_state(sr, piles).get_data()) << gs;
+}
+
ostream& operator <<(ostream& os, const move& m) {
return os << "move:(" << int(m.from)
<< "," << int(m.to)
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
index 3df9ead..564310e 100644
--- a/src/test/test_helper.h
+++ b/src/test/test_helper.h
@@ -17,7 +17,18 @@ 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 expected_moves_test(sol_rules sr, std::initializer_list<std::initializer_list<std::string>>, std::vector<move>);
+ static void expected_moves_test(sol_rules sr, std::initializer_list<std::initializer_list<std::string>>,
+ std::vector<move>);
+ static void k_plus_stock_test
+ ( sol_rules sr
+ , std::initializer_list<std::initializer_list<std::string>>
+ , std::vector<move>
+ , move
+ , pile::size_type
+ , pile::size_type
+ , card
+ , card
+ );
static bool moves_eq(std::vector<move>&, std::vector<move>&);
};
diff --git a/src/test/unit_tests/k-plus-stock-test.cpp b/src/test/unit_tests/k-plus-stock-test.cpp
new file mode 100644
index 0000000..aea5b80
--- /dev/null
+++ b/src/test/unit_tests/k-plus-stock-test.cpp
@@ -0,0 +1,297 @@
+//
+// 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_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 3, 9),
+ },
+ move(move::mtype::stock_to_waste, 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_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 3, 7),
+ },
+ move(move::mtype::stock_to_waste, 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_to_waste, 0, 4, 3)
+ },
+ move(move::mtype::stock_to_waste, 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_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 3, 9),
+ },
+ move(move::mtype::stock_to_waste, 0, 3, 9),
+ 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_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 3, 7),
+ },
+ move(move::mtype::stock_to_waste, 0, 3, 7),
+ 0, 6,
+ card(), "AD"
+ );
+}
+
+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_to_waste, 0, 4, 3)
+ },
+ move(move::mtype::stock_to_waste, 0, 4, 3),
+ 8, 0,
+ "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_to_waste, 0, 3, 9),
+ move(move::mtype::stock_to_waste, 0, 4, 3)
+ },
+ move(move::mtype::stock_to_waste, 0, 4, 3),
+ 6, 2,
+ "3C", "AH"
+ );
+}
+
+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_to_waste, 0, 3, 9),
+ move(move::mtype::stock_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 2, 6)
+ },
+ move(move::mtype::stock_to_waste, 0, 2, 6),
+ 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_to_waste, 0, 3, 8),
+ move(move::mtype::stock_to_waste, 0, 4, 3),
+ move(move::mtype::stock_to_waste, 0, 2, 9)
+ },
+ move(move::mtype::stock_to_waste, 0, 3, 8),
+ 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_to_waste, 0, 3, 9),
+ move(move::mtype::stock_to_waste, 0, 4, 3)
+ },
+ move(move::mtype::stock_to_waste, 0, 3, 9),
+ 8, 0,
+ "AS", card()
+ );
+}