forked from philsquared/hash_trie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest_RefCounts.cpp
49 lines (34 loc) · 989 Bytes
/
Test_RefCounts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "hash_trie.hpp"
#include "catch.hpp"
// These tests are only valid in a debug build
#ifdef HAMT_DEBUG_RC
TEST_CASE("ref counts") {
using namespace hamt;
node::dbg_get_total_refs() = 0;
{
hash_trie<int> h;
CHECK( h.size() == 0 );
CHECK(node::dbg_get_total_refs() == 1 );
h.insert(42);
CHECK( h.size() == 1 );
CHECK(node::dbg_get_total_refs() == 2 );
h.insert(42);
CHECK( h.size() == 1 );
CHECK(node::dbg_get_total_refs() == 2 );
h.insert(7);
CHECK( h.size() == 2 );
CHECK(node::dbg_get_total_refs() == 3 );
}
CHECK(node::dbg_get_total_refs() == 0 );
}
TEST_CASE( "hash patterns" ) {
using namespace hamt;
node::dbg_get_total_refs() = 0;
{
hash_trie<int> h;
h.insert(0b01000'00010'00001);
h.insert(0b00100'00010'00001); // differs only in third hash chunk
}
CHECK(node::dbg_get_total_refs() == 0 );
}
#endif