-
Notifications
You must be signed in to change notification settings - Fork 392
/
SingleBitContainerTest.cpp
334 lines (232 loc) · 7.69 KB
/
SingleBitContainerTest.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#include "infra/BitVector.hpp"
#include <string>
#include "gtest/gtest.h"
namespace {
class SingleBitContainerTest : public :: testing :: Test {
protected:
TR_SingleBitContainer container;
TR_SingleBitContainer other;
virtual void SetUp() {
container.resetAll(1);
other.resetAll(1);
}
};
//****** resetAll(int64_t m, int64_t n) ******//
TEST_F(SingleBitContainerTest, resetAllTest1) {
//Reseting container to false
container.set();
container.resetAll(0, 1);
ASSERT_EQ(container.isEmpty(), true) << "resetAll - bit not reset";
}
TEST_F(SingleBitContainerTest, resetAllTest2) {
//Reseting with m = 1 and n = 1, container should not be reset
container.set();
container.resetAll(1,1);
ASSERT_EQ(container.isEmpty(), false);
}
TEST_F(SingleBitContainerTest, resetAllTest3) {
//Reseting with m = 0, n = 0, container should not be reset
container.set();
container.resetAll(0,0);
ASSERT_EQ(container.isEmpty(), false);
}
//****** Test resetAll(int64_t n) *******//
TEST_F(SingleBitContainerTest, resetAllTest4) {
//Reseting with n = 0, container should not be reset
container.set();
container.resetAll(0);
ASSERT_EQ(container.isEmpty(), false) << "resetAll - invalid bit number, should not reset bit";
}
TEST_F(SingleBitContainerTest, resetAllTest5) {
//Reset the first bit
container.set();
container.resetAll(1);
ASSERT_EQ(container.isEmpty(), true) << "resetAll - bit not reset to false";
}
//****** Test setAll(int64_t m, int64_t n) ******//
TEST_F(SingleBitContainerTest, setAllTest1) {
//Set first bit to true
container.setAll(0, 1);
ASSERT_EQ(container.isEmpty(), false) << "setAll - bit not set";
}
TEST_F(SingleBitContainerTest, setAllTest2) {
//m = 1, n = 1, container should not be set
container.setAll(1,1);
ASSERT_EQ(container.isEmpty(), true);
}
TEST_F(SingleBitContainerTest, setAllTest3) {
//m = 0, n = 0, container should not be set
container.setAll(0,0);
ASSERT_EQ(container.isEmpty(), true);
}
//******* Test setAll(int64_t n) *******//
TEST_F(SingleBitContainerTest, setAllTest4) {
//setting bit to false
container.setAll(0);
ASSERT_EQ(container.isEmpty(), true);
}
TEST_F(SingleBitContainerTest, setAllTest5) {
//setting bit to true
container.setAll(1);
ASSERT_EQ(container.isEmpty(), false);
}
//******* Test intersection of two container ******//
TEST_F(SingleBitContainerTest, intersects) {
//Intersection of two false containers
container.resetAll(1);
other.resetAll(1);
ASSERT_EQ(container.intersects(other), false);
//Intersection of two true bit containers
container.setAll(1);
other.setAll(1);
ASSERT_EQ(container.intersects(other), true);
//Intersection of one false one true containers
container.resetAll(1);
other.setAll(1);
ASSERT_EQ(container.intersects(other), false);
}
//****** Test operatorEqual ******//
TEST_F(SingleBitContainerTest, operatorEqual){
//Both container set to false
container.resetAll(1);
other.resetAll(1);
ASSERT_EQ(container == other, true);
//Both container set to true
container.setAll(1);
other.setAll(1);
ASSERT_EQ(container == other, true);
//Both container set differently
container.setAll(1);
other.resetAll(1);
ASSERT_EQ(container == other, false);
}
//****** Test operatorNotEqual ******//
TEST_F(SingleBitContainerTest, operatorNotEqualTest1) {
//Both container set to false
container.resetAll(1);
other.resetAll(1);
ASSERT_EQ(container != other, false);
//Containers set differently
container.setAll(1);
other.resetAll(1);
ASSERT_EQ(container != other, true);
}
//****** Test for |= operator ******//
TEST_F(SingleBitContainerTest, bitOperator) {
//Both container set to false based on default behaviour
container |= other;
ASSERT_EQ(container.isEmpty(), true);
//Both containers set differently
container.setAll(1);
other.resetAll(1);
container |= other;
ASSERT_EQ(container.isEmpty(), false);
//other container set to true
container.resetAll(1);
other.setAll(1);
container |= other;
ASSERT_EQ(container.isEmpty(), false);
}
//****** Test for &= operator ******//
TEST_F(SingleBitContainerTest, operatorAndEqualTest) {
//Both container set to false be default
container &= other;
ASSERT_EQ(container.isEmpty(), true);
//Both container set to true
container.setAll(1);
other.setAll(1);
container &= other;
ASSERT_EQ(container.isEmpty(), false);
//other container set to false
container.setAll(1);
other.resetAll(1);
container &= other;
ASSERT_EQ(container.isEmpty(), true);
}
//****** Test for SubEqual operator ******//
TEST_F(SingleBitContainerTest, operatorSubEqualTest){
//Both container set to false by default
container -= other;
ASSERT_EQ(container.isEmpty(), true);
//other container is set to true
container.resetAll(1);
other.setAll(1);
container -= other;
ASSERT_EQ(container.isEmpty(), true);
}
//****** Test for assignment Operator *******//
TEST_F(SingleBitContainerTest, assignmentTest) {
//other is set to true
other.setAll(1);
container = other;
ASSERT_EQ(container.isEmpty(), false);
//assigning other to container
container.setAll(1);
other.resetAll(1);
container = other;
ASSERT_EQ(container.isEmpty(), true);
}
//****** Test for empty checking ******//
TEST_F(SingleBitContainerTest, emptyTest){
//Testing emptiness for a filled container
container.set();
ASSERT_EQ(container.isEmpty(), false);
//Testing emptiness for an empty container
container.empty();
ASSERT_EQ(container.isEmpty(), true);
}
//****** Test for element count ******//
TEST_F(SingleBitContainerTest, hasMoreThanOneElementTest){
//SingleBitContainer should always have one element
ASSERT_EQ(container.hasMoreThanOneElement(), false);
}
//******* Test for element count ******//
TEST_F(SingleBitContainerTest, elementCount){
//SingleBitContainer should always have one element
ASSERT_EQ(container.elementCount(), 1);
}
//****** Test for number of non-zero chunks ******//
TEST_F(SingleBitContainerTest, numUsedChunks1){
//should always have only one element in use
container.set();
ASSERT_EQ(container.numUsedChunks(), 1);
}
//****** Test for number of non-zero chunks ******//
TEST_F(SingleBitContainerTest, numNonZeroChunks) {
//testing an empty container
container.empty();
ASSERT_EQ(container.numNonZeroChunks(), 0);
//testing a filled container
container.set();
ASSERT_EQ(container.numNonZeroChunks(), 1);
}
//****** Test emptiness of container ******//
TEST_F(SingleBitContainerTest, isEmpty) {
//empty the container
container.empty();
ASSERT_EQ(container.isEmpty(), true);
//testing emptiness of filled container
container.set();
ASSERT_EQ(container.isEmpty(), false);
}
};