-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcx_multimap.cpp
More file actions
98 lines (80 loc) · 2.35 KB
/
cx_multimap.cpp
File metadata and controls
98 lines (80 loc) · 2.35 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdx/cx_multimap.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("empty and size", "[cx_multimap]") {
stdx::cx_multimap<int, int, 64> t;
CHECK(t.size() == 0);
CHECK(t.empty());
}
TEST_CASE("put and contains", "[cx_multimap]") {
stdx::cx_multimap<int, int, 64> t;
t.put(60, 40);
CHECK(t.size() == 1);
CHECK(not t.empty());
CHECK(t.contains(60));
CHECK(not t.contains(40));
CHECK(t.contains(60, 40));
CHECK(not t.contains(60, 60));
CHECK(not t.contains(40, 40));
}
TEST_CASE("constexpr empty", "[cx_multimap]") {
constexpr auto t = stdx::cx_multimap<int, int, 64>{};
STATIC_REQUIRE(t.empty());
STATIC_REQUIRE(not t.contains(10));
STATIC_REQUIRE(not t.contains(10, 10));
}
TEST_CASE("put multiple values", "[cx_multimap]") {
stdx::cx_multimap<int, int, 64> t;
t.put(60, 1);
t.put(60, 2);
t.put(60, 3);
CHECK(t.size() == 1);
CHECK(t.contains(60, 1));
CHECK(t.contains(60, 2));
CHECK(t.contains(60, 3));
CHECK(not t.contains(60, 0));
}
TEST_CASE("erase values", "[cx_multimap]") {
stdx::cx_multimap<int, int, 64> t;
t.put(60, 1);
t.put(60, 2);
t.put(61, 3);
t.put(62, 4);
CHECK(t.size() == 3);
CHECK(t.erase(60, 1));
CHECK(t.size() == 3);
CHECK(not t.contains(60, 1));
CHECK(t.contains(60, 2));
CHECK(t.erase(60, 2));
CHECK(t.size() == 2);
CHECK(not t.contains(60, 2));
CHECK(t.contains(61, 3));
CHECK(t.contains(62, 4));
t.erase(61);
CHECK(t.size() == 1);
CHECK(t.contains(62, 4));
t.erase(62);
CHECK(t.empty());
}
TEST_CASE("constexpr populated map", "[cx_multimap]") {
constexpr auto m = [] {
stdx::cx_multimap<int, int, 64> t;
t.put(10, 100);
t.put(10, 101);
t.put(10, 110);
t.put(50, 1);
return t;
}();
STATIC_REQUIRE(not m.empty());
STATIC_REQUIRE(m.size() == 2);
STATIC_REQUIRE(m.contains(10));
STATIC_REQUIRE(not m.get(10).empty());
STATIC_REQUIRE(m.get(10).size() == 3);
STATIC_REQUIRE(m.contains(10, 100));
STATIC_REQUIRE(m.contains(10, 101));
STATIC_REQUIRE(m.contains(10, 110));
STATIC_REQUIRE(not m.contains(10, 50));
STATIC_REQUIRE(not m.get(50).empty());
STATIC_REQUIRE(m.get(50).size() == 1);
STATIC_REQUIRE(m.contains(50, 1));
STATIC_REQUIRE(not m.contains(50, 2));
}