File: HashGridBox3_test.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (279 lines) | stat: -rw-r--r-- 5,498 bytes parent folder | download | duplicates (4)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>

///////////////////////////

#include <BALL/DATATYPE/hashGrid.h>
#include "HashGrid3_test.h"

///////////////////////////

START_TEST(HashGridBox3)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;

// tests for class HashGridBox3::

HashGridBox3<int>* hbox3 = 0;

CHECK(HashGridBox3() throw())
	hbox3 = new HashGridBox3<int>(0);
	TEST_NOT_EQUAL(hbox3, 0)
RESULT


CHECK(~HashGridBox3() throw())
	delete hbox3;
RESULT

CHECK(void clear() throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; ++i)
	{
		hbox.insert(i);
	}
	hbox.clear();
	TEST_EQUAL(hbox.getSize(), 0)
RESULT


CHECK(void destroy() throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; ++i)
	{
		hbox.insert(i);
	}
	hbox.destroy();
	// TODO: did it really destroy?
RESULT


CHECK(Item* find(const Item &item) throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; ++i)
	{
		hbox.insert(i);
	}
	int* found = hbox.find(3);
	TEST_NOT_EQUAL(found, 0)
	bool test = (*found == 3);
	TEST_EQUAL(test, true)
	found = hbox.find(9);
	TEST_EQUAL(found, 0)
RESULT


CHECK(const Item* find(const Item& item) const throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; ++i)
	{
		hbox.insert(i);
	}
	const int* found = hbox.find(3);
	TEST_NOT_EQUAL(found, 0)
	bool test = (*found == 3);
	TEST_EQUAL(test, true)
	found = hbox.find(9);
	TEST_EQUAL(found, 0)
RESULT


CHECK(Size getSize() const throw())
	HashGridBox3<int> hbox(0);
	int size = hbox.getSize();
	TEST_EQUAL(size, 0)
	int test_int = 5;
	hbox.insert(test_int);
	size = hbox.getSize();
	TEST_EQUAL(size, 1)
	for(int i = 0; i < 5; ++i)
	{
		hbox.insert(i);
	}
	size = hbox.getSize();
	TEST_EQUAL(size, 6)

RESULT


CHECK(void insert(const Item& item) throw())
	HashGridBox3<int> hbox(0);
	hbox.insert(567);
	bool test = (*hbox.find(567) == 567);
	TEST_EQUAL(test, true)
RESULT


CHECK(bool remove(const Item& item) throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	TEST_EQUAL(hbox.remove(3), true)
	TEST_EQUAL(hbox.getSize(), 4)
	TEST_EQUAL(hbox.find(3), 0)
	// invalid element
	TEST_EQUAL(hbox.remove(5), false)
	TEST_EQUAL(hbox.getSize(), 4)
	// remove first element
	TEST_EQUAL(hbox.remove(0), true)
	TEST_EQUAL(hbox.getSize(), 3)
	TEST_EQUAL(hbox.find(0), 0)
RESULT


CHECK(bool removeAll(const Item& item) throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	int size = hbox.getSize();
	hbox.removeAll(3);
	int new_size = hbox.getSize();
	TEST_EQUAL(size - new_size, 2)
RESULT


CHECK(bool operator == (const HashGridBox3& box) const throw())
	HashGridBox3<int> hbox1(0);
	for (int i = 0; i < 5; i++)
	{
		hbox1.insert(i);
	}
	HashGridBox3<int> hbox2(0);
	bool test = (hbox1 == hbox2);
	TEST_NOT_EQUAL(test, true);
	for (int i = 0; i < 5; i++)
	{
		hbox2.insert(i);
	}
	test = (hbox1 == hbox2);
	TEST_EQUAL(test, true);
RESULT


CHECK(bool operator != (const HashGridBox3& box) const throw())
	HashGridBox3<int> hbox1(0);
	for (int i = 0; i < 5; i++)
	{
		hbox1.insert(i);
	}
	HashGridBox3<int> hbox2(0);
	bool test = (hbox1 != hbox2);
	TEST_EQUAL(test, true);
	for (int i = 0; i < 5; i++)
	{
		hbox2.insert(i);
	}
	test = (hbox1 != hbox2);
	TEST_NOT_EQUAL(test, true);
RESULT


CHECK(bool has(const Item& item) const throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	bool test = hbox.has(8);
	TEST_NOT_EQUAL(test, true)
	test = hbox.has(0);
	TEST_EQUAL(test, true)
	test = hbox.has(4);
	TEST_EQUAL(test, true)
	test = hbox.has(3);
	TEST_EQUAL(test, true)
RESULT


CHECK(bool isEmpty() const throw())
	HashGridBox3<int> hbox(0);
	bool test = hbox.isEmpty();
	TEST_EQUAL(test, true)
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	test = hbox.isEmpty();
	TEST_EQUAL(test, false)
RESULT


CHECK(bool isValid() const throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	bool test = hbox.isValid();
	TEST_EQUAL(test, true)
RESULT


CHECK(void dump(std::ostream& s = std::cout, Size depth = 0) const throw())
	HashGridBox3<int> hbox(0);
	for (int i = 0; i < 5; i++)
	{
		hbox.insert(i);
	}
	String tmp_filename;
	NEW_TMP_FILE(tmp_filename)
	std::ofstream dump_stream(tmp_filename.c_str(), std::ios::out);
	hbox.dump(dump_stream);
	STATUS(tmp_filename)
	dump_stream.clear();
	dump_stream.close();
	TEST_FILE_REGEXP(tmp_filename.c_str(), BALL_TEST_DATA_PATH(hashgrid3_test_dump0.txt))
RESULT


CHECK(bool apply(UnaryProcessor<Item>& processor) throw())
	TestProcessor proc;
	HashGridBox3<int> hbox(0);
	hbox.insert(5);
	hbox.apply(proc);
	int* result = hbox.find(6);
	TEST_NOT_EQUAL(result, 0)
	bool test = (*result == 6);
	TEST_EQUAL(test, true)
RESULT


CHECK(bool apply(UnaryProcessor< HashGridBox3<Item> >& processor) throw())
	// ?????
RESULT

CHECK(HashGridBox3(const HashGridBox3& grid_box, bool deep = true) throw())
  // ??? Not implemented
RESULT

CHECK(const HashGridBox3& operator = (const HashGridBox3& box))
  // ???
RESULT

CHECK(void host(Visitor<HashGridBox3> &visitor) throw())
  // ???
RESULT

CHECK(void set(const HashGridBox3& box, bool /* deep */ = true))
  // ???
RESULT


/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST