aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_helper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test_helper.cpp')
-rw-r--r--src/test/test_helper.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index 14218f7..5758165 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -3,6 +3,7 @@
//
#include <rapidjson/document.h>
+#include <gtest/gtest.h>
#include "test_helper.h"
#include "../main/game/game_state.h"
@@ -10,6 +11,8 @@
#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)
+
using namespace rapidjson;
using namespace std;
@@ -18,7 +21,70 @@ bool test_helper::is_solvable(const std::string& input_file, const std::string&
const sol_rules rules = rules_parser::from_preset(preset_type);
game_state gs(rules, in_doc);
- solver sol(gs, rules);
+ solver sol(gs);
return sol.run();
}
+
+void test_helper::run_card_cache_test(sol_rules::build_policy bp,
+ bool assert_dif_col,
+ bool assert_same_col) {
+ 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;
+
+ // 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}};
+
+ cache.insert(s);
+
+ ASSERT_TRUE(cache.contains(s)) << "Contains self";
+
+ ASSERT_(assert_dif_col, hash_value(s) == hash_value(s_dif_suit))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_col.to_string();
+ ASSERT_(assert_dif_col, global_cache::game_state_pred()(s, s_dif_suit))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_col.to_string();
+ ASSERT_(assert_dif_col, cache.contains(s_dif_suit))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_col.to_string();
+
+ ASSERT_(assert_same_col, hash_value(s) == hash_value(s_same_col))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_same_col.to_string();
+ ASSERT_(assert_same_col, global_cache::game_state_pred()(s, s_same_col))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_same_col.to_string();
+ ASSERT_(assert_same_col, cache.contains(s_same_col))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_same_col.to_string();
+
+ ASSERT_FALSE(hash_value(s) == hash_value(s_dif_rank))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_rank.to_string();
+ ASSERT_FALSE(global_cache::game_state_pred()(s, s_dif_rank))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_rank.to_string();
+ ASSERT_FALSE(cache.contains(s_dif_rank))
+ << "Insert: " << c.to_string()
+ << ", Comp: " << c_dif_rank.to_string();
+ }
+ }
+
+ rules.tableau_pile_count = 0;
+ game_state _gs(rules, 0);
+}