aboutsummaryrefslogtreecommitdiff
path: root/test.cc
blob: 2c38a3f7860fecd9685f998b3342b7392f41513b (plain)
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
#include "trie.h"

#include "gtest/gtest.h"

#include <cstdint>

class TrieTest : public ::testing::Test { };

TEST_F(TrieTest, Basic) {
	Trie<uint8_t> trie;

	trie.add({1, 1, 1, 1});
	trie.add({1, 2, 1, 2});
	trie.add({2, 3, 4, 5});
	trie.add({2, 3, 1, 2});

	EXPECT_EQ(trie.resolve({1, 1, 1, 1}).first,  true);
	EXPECT_NE(trie.resolve({1, 1, 1, 1}).second, nullptr);

	EXPECT_EQ(trie.resolve({1, 2, 1, 2}).first,  true);
	EXPECT_NE(trie.resolve({1, 2, 1, 2}).second, nullptr);

	EXPECT_EQ(trie.resolve({1, 2}).first,        true);
	EXPECT_NE(trie.resolve({1, 2}).second,       nullptr);

	EXPECT_EQ(trie.resolve({1, 1, 2, 3}).first,  false);
	EXPECT_EQ(trie.resolve({1, 1, 2, 3}).second, nullptr);

	EXPECT_EQ(trie.resolve({2, 1, 4}).first,     false);
	EXPECT_EQ(trie.resolve({2, 1, 4}).second,    nullptr);
}

TEST_F(TrieTest, Remove) {
	Trie<uint8_t> trie;

	trie.add({1, 1, 1, 1});
	trie.add({1, 2, 1, 2});
	trie.add({2, 3, 4, 5});
	trie.add({2, 3, 1, 2});

	trie.remove({1, 1, 1, 1});

	EXPECT_EQ(trie.resolve({1, 1, 1, 1}).first,  false);
	EXPECT_EQ(trie.resolve({1, 1, 1, 1}).second, nullptr);

	EXPECT_EQ(trie.resolve({1, 2, 1, 2}).first,  true);
	EXPECT_NE(trie.resolve({1, 2, 1, 2}).second, nullptr);

	trie.remove({2, 3});

	EXPECT_EQ(trie.resolve({2, 3, 4, 5}).first,  false);
	EXPECT_EQ(trie.resolve({2, 3, 4, 5}).second, nullptr);

	EXPECT_EQ(trie.resolve({2, 3}).first,        false);
	EXPECT_EQ(trie.resolve({2, 3}).second,       nullptr);

	EXPECT_EQ(trie.resolve({2}).first,           true);
	EXPECT_NE(trie.resolve({2}).second,          nullptr);
}

int main(int argc, char **argv) {
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}