Lolly 1.4.28
Loading...
Searching...
No Matches
rel_hashmap_test.cpp
Go to the documentation of this file.
1#include "a_lolly_test.hpp"
2#include "rel_hashmap.hpp"
3
4TEST_CASE ("test contains") {
6
7 SUBCASE ("test case is empty") { CHECK (t->contains (1) == false); }
8
9 SUBCASE ("test case is not empty") {
10 hashmap<int, int> hm1 (0, 10);
11 hm1 (1)= 10;
12 hm1 (2)= 20;
13 t->change (hm1);
14
15 CHECK (t->contains (1) == true);
16 CHECK (t->contains (2) == true);
17 CHECK (t->contains (3) == false);
18
19 hashmap<int, int> hm2 (0, 10);
20 hm2 (3)= 30;
21 hm2 (4)= 40;
22 t->extend ();
23 t->change (hm2);
24
25 CHECK (t->contains (1) == true);
26 CHECK (t->contains (2) == true);
27 CHECK (t->contains (3) == true);
28 CHECK (t->contains (5) == false);
29 }
30}
31
32TEST_CASE ("test extend") {
34
35 hashmap<int, int> hm1 (0, 10);
36 hm1 (1)= 10;
37 hm1 (2)= 20;
38 t->change (hm1);
39 t->extend ();
40
41 CHECK (t->contains (1) == true);
42 CHECK (t->contains (2) == true);
43 CHECK (t->contains (3) == false);
44}
45
46TEST_CASE ("test shorten") {
48
49 SUBCASE ("test Shorten the empty rel_hashmap") {
50 TM_CHECK_THROWS (t->shorten ());
51 }
52
53 SUBCASE ("test not Shorten the empty rel_hashmap") {
54
55 SUBCASE ("test not throw") {
56 t->extend ();
57 CHECK_NOTHROW (t->shorten ());
58 }
59
60 SUBCASE ("test the content") {
61 t->extend ();
62 hashmap<int, int> hm1 (0, 10);
63 hm1 (1)= 10;
64 hm1 (2)= 20;
65 t->change (hm1);
66 t->shorten ();
67
68 CHECK (t->contains (1) == false);
69 CHECK (t->contains (2) == false);
70 CHECK (t->contains (4) == false);
71 CHECK (is_nil (t->next));
72 }
73 }
74}
75
76TEST_CASE ("test merge") {
78
79 SUBCASE ("test merge the empty rel_hashmap") {
80 TM_CHECK_THROWS (t->merge ());
81 }
82
83 hashmap<int, int> hm1 (0, 10);
84 hm1 (1)= 10;
85 hm1 (2)= 20;
86 t->change (hm1);
87 t->extend ();
88
89 SUBCASE ("test not merge the empty rel_hashmap") {
90
91 SUBCASE ("test not throw") {
92 t->extend ();
93 CHECK_NOTHROW (t->merge ());
94 }
95
96 SUBCASE ("test the content") {
97 t->extend ();
98 hashmap<int, int> hm2 (0, 10);
99 hm2 (3)= 30;
100 hm2 (4)= 40;
101 t->change (hm2);
102 t->merge ();
103
104 CHECK (t->contains (1) == true);
105 CHECK (t->contains (2) == true);
106 CHECK (t->contains (3) == true);
107 CHECK (t->contains (4) == true);
108 CHECK (t->contains (5) == false);
109 }
110 }
111}
112
113TEST_CASE ("test find_changes") {
115 hashmap<int, int> hm1 (0, 10);
116 hm1 (1)= 10;
117 hm1 (2)= 20;
118 t->change (hm1);
119
120 SUBCASE ("test if all the same") {
121 hashmap<int, int> hm2 (0, 10);
122 hm2 (1)= 10;
123 hm2 (2)= 20;
124 t->find_changes (hm2);
125
126 CHECK (hm2->contains (1) == false);
127 CHECK (hm2->contains (2) == false);
128 }
129
130 SUBCASE ("test if not same") {
131 hashmap<int, int> hm2 (0, 10);
132 hm2 (1)= 10;
133 hm2 (2)= 30;
134 t->find_changes (hm2);
135
136 CHECK (hm2->contains (1) == false);
137 CHECK (hm2[2] == 30);
138 }
139
140 SUBCASE ("test if all different") {
141 hashmap<int, int> hm2 (0, 10);
142 hm2 (1)= 20;
143 hm2 (2)= 30;
144 t->find_changes (hm2);
145
146 CHECK (hm2[1] == 20);
147 CHECK (hm2[2] == 30);
148 }
149}
150
151TEST_CASE ("test find_differences") {
153 hashmap<int, int> hm1 (0, 10);
154 hm1 (1)= 10;
155 hm1 (2)= 20;
156 t->change (hm1);
157
158 SUBCASE ("test if all the same") {
159 hashmap<int, int> hm2 (0, 10);
160 hm2 (1)= 10;
161 hm2 (2)= 20;
162 t->find_differences (hm2);
163
164 CHECK (hm2->contains (1) == false);
165 CHECK (hm2->contains (2) == false);
166 }
167
168 t->extend ();
169 hashmap<int, int> hm2 (0, 10);
170 hm1 (3)= 30;
171 hm1 (4)= 40;
172 t->change (hm2);
173
174 SUBCASE ("test if key different") {
175
176 SUBCASE ("test if different from first, but the same as next") {
177 hashmap<int, int> hm3 (0, 10);
178 hm3 (3)= 30;
179 hm3 (4)= 40;
180 t->find_differences (hm3);
181
182 CHECK (hm3->contains (1) == false);
183 CHECK (hm3->contains (2) == false);
184 CHECK (hm3->contains (1) == false);
185 CHECK (hm3->contains (2) == false);
186 }
187
188 SUBCASE ("test if different from all the others") {
189 hashmap<int, int> hm3 (0, 10);
190 hm3 (5)= 30;
191 hm3 (6)= 40;
192 t->find_differences (hm3);
193
194 CHECK (hm3->contains (1) == false);
195 CHECK (hm3->contains (2) == false);
196 CHECK (hm3[5] == 30);
197 CHECK (hm3[6] == 40);
198
199 hashmap<int, int> hm4 (0, 10);
200 hm4 (3)= 40;
201 hm4 (4)= 50;
202 t->find_differences (hm4);
203
204 CHECK (hm4->contains (1) == false);
205 CHECK (hm4->contains (2) == false);
206 CHECK (hm4[3] == 40);
207 CHECK (hm4[4] == 50);
208 }
209 }
210}
211
212TEST_CASE ("test change") {
214 hashmap<int, int> hm1 (0, 10);
215 hm1 (1)= 10;
216 hm1 (2)= 20;
217 t->change (hm1);
218
219 CHECK (t->contains (1));
220 CHECK (t->contains (2));
221
222 SUBCASE ("test change the same") {
223 hashmap<int, int> hm2 (0, 10);
224 hm2 (1)= 10;
225 hm2 (2)= 20;
226 t->change (hm2);
227
228 CHECK (t->contains (1));
229 CHECK (t->contains (2));
230
231 hashmap<int, int> hm3 (0, 10);
232 hm3 (1)= 20;
233 hm3 (2)= 30;
234 t->change (hm3);
235
236 CHECK (t[1] == 20);
237 CHECK (t[2] == 30);
238 }
239
240 SUBCASE ("test change the different") {
241 hashmap<int, int> hm2 (0, 10);
242 hm2 (3)= 30;
243 hm2 (4)= 40;
244 t->change (hm2);
245
246 CHECK (t[1] == 10);
247 CHECK (t[2] == 20);
248 CHECK (t[3] == 30);
249 CHECK (t[4] == 40);
250 }
251
252 SUBCASE ("test change the next") {
253 t->extend ();
254 hashmap<int, int> hm2 (0, 10);
255 hm2 (3)= 30;
256 hm2 (4)= 40;
257 t->change (hm2);
258
259 CHECK (t[1] == 10);
260 CHECK (t[2] == 20);
261 CHECK (t[3] == 30);
262 CHECK (t[4] == 40);
263 }
264}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
blackbox t[13]
The list class represents a linked list.
Definition list.hpp:48
#define TM_CHECK_THROWS(statements)
TEST_CASE("test for operator+= and advance()")