SpiecsEngine
 
Loading...
Searching...
No Matches
LinkedUnorderedMap_test.h
Go to the documentation of this file.
1/**
2* @file LinkedUnorderedMap_test.h.
3* @brief The LinkedUnorderedMap_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Container/LinkedUnorderedMap.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief The interface is inherited from testing::Test.
16 * Registry on Initialize.
17 */
19 {
20 protected:
21
22 /**
23 * @brief Testing class initialize function.
24 */
25 void SetUp() override {
26
27 c0.push_back("aaa", "aaa");
28 c0.push_back("bbb", "bbb");
29 c0.push_back("ccc", "ccc");
30
31 c1.push_back(1, "1");
32 c1.push_back(2, "2");
33 c1.push_back(3, "3");
34
35 c2.push_back(1.0f, "1.0");
36 c2.push_back(2.0f, "2.0");
37 c2.push_back(3.0f, "3.0");
38 }
39
40 /**
41 * @brief Testing class TearDown function.
42 */
44
45 scl::linked_unordered_map<std::string, std::string> c0; /* @brief Test Item. */
46 scl::linked_unordered_map<int, std::string> c1; /* @brief Test Item. */
47 scl::linked_unordered_map<float, std::string> c2; /* @brief Test Item. */
48 };
49
50 /**
51 * @brief Testing if initialize successfully.
52 */
54
56
57 /**
58 * @brief Testing initialized container's size.
59 */
60 EXPECT_EQ(c0.size(), 3);
61 EXPECT_EQ(c1.size(), 3);
62 EXPECT_EQ(c2.size(), 3);
63
64 /**
65 * @brief Testing initialized container's euqlity.
66 */
67 EXPECT_EQ(c0.has_equal_size(), true);
68 EXPECT_EQ(c1.has_equal_size(), true);
69 EXPECT_EQ(c2.has_equal_size(), true);
70 }
71
72 /**
73 * @brief Testing if Remove element successfully.
74 */
76
78
79 /**
80 * @brief Testing if clear successfully.
81 */
82 c0.clear();
83 EXPECT_EQ(c0.size(), 0);
84
85 /**
86 * @brief Testing if erase successfully.
87 */
88 c1.erase(1);
89 EXPECT_EQ(c1.size(), 2);
90
91 c2.erase(2.0f);
92 c2.erase(3.0f);
93 EXPECT_EQ(c2.size(), 1);
94
95 /**
96 * @brief Testing if erase the element not in this container,
97 */
98 c1.erase(10);
99 EXPECT_EQ(c1.size(), 2);
100
101 /**
102 * @brief Testing container's euqlity after remove element.
103 */
104 EXPECT_EQ(c0.has_equal_size(), true);
105 EXPECT_EQ(c1.has_equal_size(), true);
106 EXPECT_EQ(c2.has_equal_size(), true);
107 }
108
109 /**
110 * @brief Testing if Find element successfully.
111 */
113
115
116 /**
117 * @brief Testing if find a exist element successfully.
118 */
119 auto v = c0.find_value("aaa");
120 EXPECT_EQ(*v, "aaa");
121
122 /**
123 * @brief Testing if find a not exist element successfully.
124 */
125 const bool isHasValue = c1.has_key(10);
126 EXPECT_EQ(isHasValue, false);
127
128 /**
129 * @brief Testing if find a not exist element successfully.
130 */
131 v = c2.find_value(10.0);
132 EXPECT_EQ(v, nullptr);
133
134 /**
135 * @brief Testing container's euqlity after find element.
136 */
137 EXPECT_EQ(c0.has_equal_size(), true);
138 EXPECT_EQ(c1.has_equal_size(), true);
139 EXPECT_EQ(c2.has_equal_size(), true);
140 }
141
142 /**
143 * @brief Testing if Add element successfully.
144 */
146
148
149 /**
150 * @brief Testing if insert a new element successfully.
151 */
152 c0.push_back("ddd", "ddd");
153 EXPECT_EQ(c0.size(), 4);
154
155 /**
156 * @brief Testing if insert a repeat element successfully.
157 */
158 c1.push_back(1, "1");
159 EXPECT_EQ(c1.size(), 3);
160
161 /**
162 * @brief Testing if the insert element written successfully.
163 */
164 auto v = c2.find_value(1.0f);
165 EXPECT_EQ(*v, "1.0");
166 c2.push_back(1.0f, "10.0");
167 v = c2.find_value(1.0f);
168 EXPECT_EQ(*v, "10.0");
169
170 /**
171 * @brief Testing container's euqlity after add element.
172 */
173 EXPECT_EQ(c0.has_equal_size(), true);
174 EXPECT_EQ(c1.has_equal_size(), true);
175 EXPECT_EQ(c2.has_equal_size(), true);
176 }
177
178 /**
179 * @brief Testing if Iter in correct order successfully.
180 */
182
184
185 /**
186 * @brief Testing the initialized container's order.
187 */
188 std::vector<std::string> iterOrder0;
189 c0.for_each([&](const std::string& k, const std::string& v) {
190 iterOrder0.push_back(k);
191 return false;
192 });
193 EXPECT_EQ(iterOrder0[0], "aaa");
194 EXPECT_EQ(iterOrder0[1], "bbb");
195 EXPECT_EQ(iterOrder0[2], "ccc");
196
197 /**
198 * @brief Testing erase's influence in for_each order.
199 */
200 std::vector<int> iterOrder1;
201 c1.erase(2);
202 c1.for_each([&](const int& k, const std::string& v) {
203 iterOrder1.push_back(k);
204 return false;
205 });
206 EXPECT_EQ(iterOrder1[0], 1);
207 EXPECT_EQ(iterOrder1[1], 3);
208
209 /**
210 * @brief Testing insert's influence in for_each order.
211 */
212 std::vector<float> iterOrder2;
213 c2.push_back(0.5f, "0.5");
214 c2.for_each([&](const float& k, const std::string& v) {
215 iterOrder2.push_back(k);
216 return false;
217 });
218 EXPECT_EQ(iterOrder2[0], 1.0f);
219 EXPECT_EQ(iterOrder2[1], 2.0f);
220 EXPECT_EQ(iterOrder2[2], 3.0f);
221 EXPECT_EQ(iterOrder2[3], 0.5f);
222
223 /**
224 * @brief Testing container's euqlity after iter.
225 */
226 EXPECT_EQ(c0.has_equal_size(), true);
227 EXPECT_EQ(c1.has_equal_size(), true);
228 EXPECT_EQ(c2.has_equal_size(), true);
229 }
230
231 /**
232 * @brief Testing if No Linear Finding is successfully.
233 */
235
237
238 /**
239 * @brief Testing prev_value is getted successfully.
240 */
241 EXPECT_EQ(c0.prev_value("aaa"), nullptr);
242 EXPECT_EQ(*c0.prev_value("bbb"), "aaa");
243 EXPECT_EQ(*c0.prev_value("ccc"), "bbb");
244
245 /**
246 * @brief Testing next_value is getted successfully.
247 */
248 EXPECT_EQ(*c0.next_value("aaa"), "bbb");
249 EXPECT_EQ(*c0.next_value("bbb"), "ccc");
250 EXPECT_EQ(c0.next_value("ccc"), nullptr);
251
252 /**
253 * @breif Testing first value is getted successfully.
254 */
255 scl::linked_unordered_map<std::string, std::string> c3;
256
257 EXPECT_EQ(*c0.first(), "aaa");
258 EXPECT_EQ(*c1.first(), "1");
259 EXPECT_EQ(*c2.first(), "1.0");
260 EXPECT_EQ(c3.first(), nullptr);
261
262 /**
263 * @breif Testing end value is getted successfully.
264 */
265 EXPECT_EQ(*c0.end(), "ccc");
266 EXPECT_EQ(*c1.end(), "3");
267 EXPECT_EQ(*c2.end(), "3.0");
268 EXPECT_EQ(c3.end(), nullptr);
269
270 /**
271 * @breif Testing end key is getted successfully.
272 */
273 EXPECT_EQ(*c0.end_k(), "ccc");
274 EXPECT_EQ(*c1.end_k(), 3);
275 EXPECT_EQ(*c2.end_k(), 3.0);
276 EXPECT_EQ(c3.end_k(), nullptr);
277
278 /**
279 * @brief Testing container's euqlity after NoLinearFind.
280 */
281 EXPECT_EQ(c0.has_equal_size(), true);
282 EXPECT_EQ(c1.has_equal_size(), true);
283 EXPECT_EQ(c2.has_equal_size(), true);
284 EXPECT_EQ(c3.has_equal_size(), true);
285 }
286}
#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.
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.
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...
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(directed_acyclic_graph_test, Addnode)
Testing if add node successfully.
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
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start