SpiecsEngine
 
Loading...
Searching...
No Matches
RadixTrie_test.h
Go to the documentation of this file.
1/**
2* @file RadixTrie_test.h.
3* @brief The RadixTrie_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Container/RadixTrie.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief Testing scl::radix_trie<BITS, 1>
16 */
18
20
21 static constexpr uint64_t n = 1 << 19;
22
23 std::vector<uint64_t> vs;
24 vs.resize(n);
25
26 std::unordered_map<uint64_t, void*> map;
27 for (uint64_t i = 0; i < n; i++)
28 {
29 map[i] = &vs[i];
30 }
31
32 scl::radix_trie<19, 1> rt;
33 for (uint64_t i = 0; i < n; i++)
34 {
35 rt.set(i, &vs[i]);
36 }
37
38 {
39 SPICESTEST_PROFILE_SCOPE("Hash map");
40
41 for (uint64_t i = 0; i < n; i++)
42 {
43 EXPECT_NE(map.find(i), map.end());
44 EXPECT_EQ(map[i], &vs[i]);
45 }
46 }
47
48 {
49 SPICESTEST_PROFILE_SCOPE("radix_trie<BITS, 1>");
50
51 for (uint64_t i = 0; i < n; i++)
52 {
53 EXPECT_EQ(rt.get(i), &vs[i]);
54 }
55 }
56 }
57
58 /**
59 * @brief Testing scl::radix_trie<BITS, 2>
60 */
62
64
65 static constexpr uint64_t n = 1 << 19;
66
67 std::vector<uint64_t> vs;
68 vs.resize(n);
69
70 std::unordered_map<uint64_t, void*> map;
71 for (uint64_t i = 0; i < n; i++)
72 {
73 map[i] = &vs[i];
74 }
75
76 scl::radix_trie<19, 2> rt;
77 for (uint64_t i = 0; i < n; i++)
78 {
79 rt.set(i, &vs[i]);
80 }
81
82 {
83 SPICESTEST_PROFILE_SCOPE("Hash map");
84
85 for (uint64_t i = 0; i < n; i++)
86 {
87 EXPECT_NE(map.find(i), map.end());
88 EXPECT_EQ(map[i], &vs[i]);
89 }
90 }
91
92 {
93 SPICESTEST_PROFILE_SCOPE("radix_trie<BITS, 2>");
94
95 for (uint64_t i = 0; i < n; i++)
96 {
97 void* p = rt.get(i);
98
99 EXPECT_EQ(p, &vs[i]);
100 }
101 }
102 }
103
104 /**
105 * @brief Testing scl::radix_trie<BITS, 3>
106 */
108
110
111 static constexpr uint64_t n = 1 << 19;
112
113 std::vector<uint64_t> vs;
114 vs.resize(n);
115
116 std::unordered_map<uint64_t, void*> map;
117 for (uint64_t i = 0; i < n; i++)
118 {
119 map[i] = &vs[i];
120 }
121
122 scl::radix_trie<51, 3> rt;
123 for (uint64_t i = 0; i < n; i++)
124 {
125 rt.set(i, &vs[i]);
126 }
127
128 {
129 SPICESTEST_PROFILE_SCOPE("Hash map");
130
131 for (uint64_t i = 0; i < n; i++)
132 {
133 EXPECT_NE(map.find(i), map.end());
134 EXPECT_EQ(map[i], &vs[i]);
135 }
136 }
137
138 {
139 SPICESTEST_PROFILE_SCOPE("radix_trie<BITS, 3>");
140
141 for (uint64_t i = 0; i < n; i++)
142 {
143 EXPECT_EQ(rt.get(i), &vs[i]);
144 }
145 }
146 }
147}
#define SPICES_FUNC_SIG
#define SPICESTEST_PROFILE_SCOPE_LINE2(name, line)
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICES_PROFILE
#define SPICESTEST_PROFILE_END_SESSION()
#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath)
#define SPICESTEST_PROFILE_SCOPE_LINE(name, line)
#define SPICESTEST_PROFILE_FUNCTION()
InstrumentationTimer(const char *name)
std::chrono::time_point< std::chrono::steady_clock > m_StartTimepoint
Instrumentor(Instrumentor &&)=delete
static Instrumentor & Get()
void BeginSession(const std::string &name, const std::string &filepath="results.json")
void WriteProfile(const ProfileResult &result)
InstrumentationSession * m_CurrentSession
std::ofstream m_OutputStream
Instrumentor(const Instrumentor &)=delete
void Test(float f)
Basic Override Class Function.
void Test()
Basic Override Class Function.
void TearDown() override
Testing class TearDown function.
std::vector< scl::directed_acyclic_node > m_Nodes
void SetUp() override
Testing class initialize function.
The interface is inherited from testing::Test. Registy on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
The interface is inherited from testing::Test. Registry on Initialize.
scl::kd_tree< 2 > m_KDTree
Create a KDTree with 2 dimensions.
Definition KDTree_test.h:57
void TearDown() override
Testing class TearDown function.
Definition KDTree_test.h:52
void SetUp() override
Testing class initialize function.
Definition KDTree_test.h:27
The interface is inherited from testing::Test. Registry on Initialize.
Definition KDTree_test.h:21
scl::linked_unordered_map< int, std::string > c1
scl::linked_unordered_map< float, std::string > c2
scl::linked_unordered_map< std::string, std::string > c0
void SetUp() override
Testing class initialize function.
void TearDown() override
Testing class TearDown function.
The interface is inherited from testing::Test. Registry on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
Testing class TearDown function.
Unit Test for RuntimeMemoryBlock.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
The interface is inherited from testing::Test. Registry on Initialize.
bool Empty() const
Determine if this list is empty.
Definition FreeList.h:50
void Push(void *obj)
Recycle a object memory to this free list.
Definition FreeList.cpp:13
void *& Begin()
Get current pointer (no const & reference version).
Definition FreeList.h:94
void *& End()
Get end pointer (no const & reference version).
Definition FreeList.h:100
Free list for memory pool.
Definition FreeList.h:16
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...
Definition KDTree.h:27
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...
void build()
Malloc a memory to begin_.
void add_element(const std::string &name, const std::string &type)
Add a element to object_, means a memory block will be occupied with given param type.
runtime_memory_block()=default
Constructor Function.
void * get_addr() const
Get the begin_.
The container is wrapper of a continue memory block. Used in Material::BuildMaterial(),...
Bidirectional cyclic linked list for span.
Definition SpanList.h:73
span * m_Next
next span.
Definition SpanList.h:41
span * m_Prev
previous span.
Definition SpanList.h:46
Used for manage multiple page memory.
Definition SpanList.h:15
int main(int argc, char **argv)
The Entry of SpicesTest.
Definition main.cpp:76
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
TEST_F(free_list_test, PushPop)
Testing scl::free_list::Push/Pop.
TEST_F(runtime_memory_block_test, Initialize)
Testing if initialize successfully.
TEST_F(directed_acyclic_graph_test, Addnode)
Testing if add node successfully.
TEST_F(span_list_test, Initialize)
Testing scl::span_list::Initialize.
TEST_F(linked_unordered_map_test, Initialize)
Testing if initialize successfully.
TEST_F(kd_tree_test, Insert)
Testing if Insert successfully.
Definition KDTree_test.h:63
TEST(tuple_test, IterTuple)
Testing std::tuple Helper Function.
Definition Tuple_test.h:17
void IterTuple(Tuple &tuple, Function &&f)
Iter a tuple.
Definition Tuple.h:34
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start