-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
74 lines (58 loc) · 1.54 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "trie.hpp"
struct Data {
int a = 0;
int b = 0;
};
TEST_CASE("Trie insertion")
{
TrieNode<Data, 256> root;
root.insert("abc", {2, 3});
root.insert("abcd", {4, 5});
}
TEST_CASE("Trie try_insert")
{
TrieNode<Data, 256> root;
auto val = root.try_insert("abc", {2, 3});
CHECK(root.find("abc") != nullptr);
CHECK(root.find("abc")->a == 2);
CHECK(val->a == root.find("abc")->a);
val = root.try_insert("abc", {5, 6});
CHECK(root.find("abc") != nullptr);
CHECK(root.find("abc")->a == 2);
CHECK(val->a == root.find("abc")->a);
}
TEST_CASE("Trie searching")
{
TrieNode<Data, 256> root;
root.insert("abc", {2, 3});
root.insert("abcd", {4, 5});
CHECK(root.find("abc") != nullptr);
CHECK(root.find("abc")->a == 2);
CHECK(root.find("abc")->b == 3);
CHECK(root.find("abcd") != nullptr);
CHECK(root.find("abcd")->a == 4);
CHECK(root.find("abcd")->b == 5);
CHECK(root.find("") == nullptr);
CHECK(root.find("asdf") == nullptr);
}
TEST_CASE("Trie erasing")
{
TrieNode<Data, 256> root;
root.insert("abc", {2, 3});
root.insert("abcd", {4, 5});
root.erase("abc");
CHECK(root.find("abc") == nullptr);
CHECK(root.find("abcd")->a == 4);
}
TEST_CASE("Trie get_all")
{
TrieNode<Data, 256> root;
root.insert("abc", {2, 3});
root.insert("abcd", {4, 5});
auto a = root.get_all();
for (const auto& b : a) {
std::cerr << b.first << ", " << b.second->a << std::endl;
}
}