From 252c7398925b5267963c1a48251cd7ba2d4ec381 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 25 Jan 2018 15:20:54 +0000 Subject: Refactor game_state & cache to remove static hack --- src/test/test_helper.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/test/test_helper.cpp') diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 5758165..81f11e7 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -11,7 +11,7 @@ #include "../main/input-output/input/json-parsing/json_helper.h" #include "../main/input-output/input/json-parsing/rules_parser.h" -#define ASSERT_(t_f, statement) ASSERT_TRUE((statement) == t_f) +#define ASSERT_(t_f, statement) ASSERT_TRUE((statement) == (t_f)) using namespace rapidjson; using namespace std; @@ -36,7 +36,7 @@ void test_helper::run_card_cache_test(sol_rules::build_policy bp, for (uint8_t suit_idx = 0; suit_idx < 4; suit_idx++) { for (card::rank_t rank = 1; rank <= 13; rank++) { - global_cache cache; + global_cache cache(gs); // c2 is the same as c_ but with a different suit const card c = card(suit_idx, rank); @@ -49,42 +49,39 @@ void test_helper::run_card_cache_test(sol_rules::build_policy bp, const game_state s_same_col = {{c_same_col}}; const game_state s_dif_rank = {{c_dif_rank}}; - cache.insert(s); + cache.insert(s.get_data()); - ASSERT_TRUE(cache.contains(s)) << "Contains self"; + ASSERT_TRUE(cache.contains(s.get_data())) << "Contains self"; - ASSERT_(assert_dif_col, hash_value(s) == hash_value(s_dif_suit)) + ASSERT_(assert_dif_col, hasher(gs)(s.get_data()) == hasher(gs)(s_dif_suit.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_dif_col, global_cache::game_state_pred()(s, s_dif_suit)) + ASSERT_(assert_dif_col, predicate(gs)(s.get_data(), s_dif_suit.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_dif_col, cache.contains(s_dif_suit)) + ASSERT_(assert_dif_col, cache.contains(s_dif_suit.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_same_col, hash_value(s) == hash_value(s_same_col)) + ASSERT_(assert_same_col, hasher(gs)(s.get_data()) == hasher(gs)(s_same_col.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_same_col.to_string(); - ASSERT_(assert_same_col, global_cache::game_state_pred()(s, s_same_col)) + ASSERT_(assert_same_col, predicate(gs)(s.get_data(), s_same_col.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_same_col.to_string(); - ASSERT_(assert_same_col, cache.contains(s_same_col)) + ASSERT_(assert_same_col, cache.contains(s_same_col.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_same_col.to_string(); - ASSERT_FALSE(hash_value(s) == hash_value(s_dif_rank)) + ASSERT_FALSE(hasher(gs)(s.get_data()) == hasher(gs)(s_dif_rank.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_rank.to_string(); - ASSERT_FALSE(global_cache::game_state_pred()(s, s_dif_rank)) + ASSERT_FALSE(predicate(gs)(s.get_data(), s_dif_rank.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_rank.to_string(); - ASSERT_FALSE(cache.contains(s_dif_rank)) + ASSERT_FALSE(cache.contains(s_dif_rank.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_rank.to_string(); } } - - rules.tableau_pile_count = 0; - game_state _gs(rules, 0); } -- cgit v1.2.1 From 9b2429c349d4cae96a244fbbedb598f59c2718c8 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 30 Jan 2018 15:51:37 +0000 Subject: Update tests to use new game_state constructor --- src/test/test_helper.cpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/test/test_helper.cpp') diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp index 81f11e7..22499de 100644 --- a/src/test/test_helper.cpp +++ b/src/test/test_helper.cpp @@ -32,54 +32,44 @@ void test_helper::run_card_cache_test(sol_rules::build_policy bp, sol_rules rules; rules.tableau_pile_count = 1; rules.build_pol = bp; - game_state gs(rules, 0); for (uint8_t suit_idx = 0; suit_idx < 4; suit_idx++) { for (card::rank_t rank = 1; rank <= 13; rank++) { - global_cache cache(gs); - // c2 is the same as c_ but with a different suit const card c = card(suit_idx, rank); const card c_dif_col = card(uint8_t((suit_idx + 1) % 4), rank); const card c_same_col = card(uint8_t((suit_idx + 2) % 4), rank); const card c_dif_rank = card(suit_idx, card::rank_t((rank % 13) + 1)); - const game_state s = {{c}}; - const game_state s_dif_suit = {{c_dif_col}}; - const game_state s_same_col = {{c_same_col}}; - const game_state s_dif_rank = {{c_dif_rank}}; + const game_state s = game_state(rules, initializer_list{{c}}); + const game_state s_dif_suit(rules, initializer_list{{c_dif_col}}); + const game_state s_same_col(rules, initializer_list{{c_same_col}}); + const game_state s_dif_rank(rules, initializer_list{{c_dif_rank}}); - cache.insert(s.get_data()); + global_cache cache(s); - ASSERT_TRUE(cache.contains(s.get_data())) << "Contains self"; + cache.insert(s); - ASSERT_(assert_dif_col, hasher(gs)(s.get_data()) == hasher(gs)(s_dif_suit.get_data())) - << "Insert: " << c.to_string() - << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_dif_col, predicate(gs)(s.get_data(), s_dif_suit.get_data())) + ASSERT_TRUE(cache.contains(s)) << "Contains self"; + + ASSERT_(assert_dif_col, hasher(s)(s.get_data()) == hasher(s)(s_dif_suit.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_dif_col, cache.contains(s_dif_suit.get_data())) + ASSERT_(assert_dif_col, cache.contains(s_dif_suit)) << "Insert: " << c.to_string() << ", Comp: " << c_dif_col.to_string(); - ASSERT_(assert_same_col, hasher(gs)(s.get_data()) == hasher(gs)(s_same_col.get_data())) + ASSERT_(assert_same_col, hasher(s)(s.get_data()) == hasher(s)(s_same_col.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_same_col.to_string(); - ASSERT_(assert_same_col, predicate(gs)(s.get_data(), s_same_col.get_data())) - << "Insert: " << c.to_string() - << ", Comp: " << c_same_col.to_string(); - ASSERT_(assert_same_col, cache.contains(s_same_col.get_data())) + ASSERT_(assert_same_col, cache.contains(s_same_col)) << "Insert: " << c.to_string() << ", Comp: " << c_same_col.to_string(); - ASSERT_FALSE(hasher(gs)(s.get_data()) == hasher(gs)(s_dif_rank.get_data())) - << "Insert: " << c.to_string() - << ", Comp: " << c_dif_rank.to_string(); - ASSERT_FALSE(predicate(gs)(s.get_data(), s_dif_rank.get_data())) + ASSERT_FALSE(hasher(s)(s.get_data()) == hasher(s)(s_dif_rank.get_data())) << "Insert: " << c.to_string() << ", Comp: " << c_dif_rank.to_string(); - ASSERT_FALSE(cache.contains(s_dif_rank.get_data())) + ASSERT_FALSE(cache.contains(s_dif_rank)) << "Insert: " << c.to_string() << ", Comp: " << c_dif_rank.to_string(); } -- cgit v1.2.1