aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/global_cache_test.cpp (renamed from src/test/gloabl_cache_test.cpp)15
-rw-r--r--src/test/test_helper.cpp29
2 files changed, 16 insertions, 28 deletions
diff --git a/src/test/gloabl_cache_test.cpp b/src/test/global_cache_test.cpp
index beb1e0f..69bfc91 100644
--- a/src/test/gloabl_cache_test.cpp
+++ b/src/test/global_cache_test.cpp
@@ -31,7 +31,7 @@ TEST(GlobalCache, CommutativeTableauPiles) {
rules.tableau_pile_count = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
game_state gs(rules, 0);
- global_cache cache;
+ global_cache cache(gs);
cache.insert ({{card("AC")},{card("2D")},{card("3H")}});
ASSERT_TRUE (cache.contains({{card("2D")},{card("3H")},{card("AC")}}));
@@ -48,9 +48,6 @@ TEST(GlobalCache, CommutativeTableauPiles) {
cache.insert ({{card("6C"),card("7D")},{card("8C")},{card("9D")}});
ASSERT_TRUE (cache.contains({{card("8C")},{card("6C"),card("7D")},{card("9D")}}));
ASSERT_FALSE(cache.contains({{card("8C")},{card("6C"),card("KD")},{card("9D")}}));
-
- rules.tableau_pile_count = 0;
- game_state _gs(rules, 0);
}
TEST(GlobalCache, CommutativeReserve) {
@@ -58,7 +55,7 @@ TEST(GlobalCache, CommutativeReserve) {
rules.reserve_size = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
game_state gs(rules, 0);
- global_cache cache;
+ global_cache cache(gs);
cache.insert ({{card("AC")},{card("2D")},{card("3H")}});
ASSERT_TRUE (cache.contains({{card("2D")},{card("3H")},{card("AC")}}));
@@ -75,9 +72,6 @@ TEST(GlobalCache, CommutativeReserve) {
cache.insert ({{card("6C"),card("7D")},{card("8C")},{card("9D")}});
ASSERT_TRUE (cache.contains({{card("8C")},{card("6C"),card("7D")},{card("9D")}}));
ASSERT_FALSE(cache.contains({{card("8C")},{card("6C"),card("KD")},{card("9D")}}));
-
- rules.reserve_size = 0;
- game_state _gs(rules, 0);
}
TEST(GlobalCache, CommutativeCells) {
@@ -85,7 +79,7 @@ TEST(GlobalCache, CommutativeCells) {
rules.cells = 3;
rules.build_pol = sol_rules::build_policy::SAME_SUIT;
game_state gs(rules, 0);
- global_cache cache;
+ global_cache cache(gs);
cache.insert ({{card("AC")},{card("2D")},{card("3H")}});
ASSERT_TRUE (cache.contains({{card("2D")},{card("3H")},{card("AC")}}));
@@ -96,7 +90,4 @@ TEST(GlobalCache, CommutativeCells) {
cache.insert ({{card("4C")},{card("5D")},{}});
ASSERT_TRUE (cache.contains({{},{card("4C")},{card("5D")}}));
ASSERT_FALSE(cache.contains({{},{card("4C")},{}}));
-
- rules.cells = 0;
- game_state _gs(rules, 0);
}
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);
}