Skip to content

Commit 2ada678

Browse files
committed
Use randbits instead of ad-hoc emulation in prevector tests
1 parent 5f0b04e commit 2ada678

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/test/prevector_tests.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,67 +198,65 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
198198
for (int j = 0; j < 64; j++) {
199199
prevector_tester<8, int> test;
200200
for (int i = 0; i < 2048; i++) {
201-
int r = insecure_rand();
202-
if ((r % 4) == 0) {
201+
if (insecure_randbits(2) == 0) {
203202
test.insert(insecure_randrange(test.size() + 1), insecure_rand());
204203
}
205-
if (test.size() > 0 && ((r >> 2) % 4) == 1) {
204+
if (test.size() > 0 && insecure_randbits(2) == 1) {
206205
test.erase(insecure_randrange(test.size()));
207206
}
208-
if (((r >> 4) % 8) == 2) {
207+
if (insecure_randbits(3) == 2) {
209208
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (insecure_randrange(5)) - 2));
210209
test.resize(new_size);
211210
}
212-
if (((r >> 7) % 8) == 3) {
211+
if (insecure_randbits(3) == 3) {
213212
test.insert(insecure_randrange(test.size() + 1), 1 + insecure_randrange(2), insecure_rand());
214213
}
215-
if (((r >> 10) % 8) == 4) {
214+
if (insecure_randbits(3) == 4) {
216215
int del = std::min<int>(test.size(), 1 + (insecure_randrange(2)));
217216
int beg = insecure_randrange(test.size() + 1 - del);
218217
test.erase(beg, beg + del);
219218
}
220-
if (((r >> 13) % 16) == 5) {
219+
if (insecure_randbits(4) == 5) {
221220
test.push_back(insecure_rand());
222221
}
223-
if (test.size() > 0 && ((r >> 17) % 16) == 6) {
222+
if (test.size() > 0 && insecure_randbits(4) == 6) {
224223
test.pop_back();
225224
}
226-
if (((r >> 21) % 32) == 7) {
225+
if (insecure_randbits(5) == 7) {
227226
int values[4];
228227
int num = 1 + (insecure_randrange(4));
229228
for (int k = 0; k < num; k++) {
230229
values[k] = insecure_rand();
231230
}
232231
test.insert_range(insecure_randrange(test.size() + 1), values, values + num);
233232
}
234-
if (((r >> 26) % 32) == 8) {
233+
if (insecure_randbits(5) == 8) {
235234
int del = std::min<int>(test.size(), 1 + (insecure_randrange(4)));
236235
int beg = insecure_randrange(test.size() + 1 - del);
237236
test.erase(beg, beg + del);
238237
}
239-
r = insecure_rand();
240-
if (r % 32 == 9) {
238+
if (insecure_randbits(5) == 9) {
241239
test.reserve(insecure_randrange(32));
242240
}
243-
if ((r >> 5) % 64 == 10) {
241+
if (insecure_randbits(6) == 10) {
244242
test.shrink_to_fit();
245243
}
246244
if (test.size() > 0) {
247245
test.update(insecure_randrange(test.size()), insecure_rand());
248246
}
249-
if (((r >> 11) % 1024) == 11) {
247+
if (insecure_randbits(10) == 11) {
250248
test.clear();
251249
}
252-
if (((r >> 21) % 512) == 12) {
250+
if (insecure_randbits(9) == 12) {
253251
test.assign(insecure_randrange(32), insecure_rand());
254252
}
255-
if (((r >> 15) % 8) == 3) {
253+
if (insecure_randbits(3) == 3) {
256254
test.swap();
257255
}
258-
if (((r >> 15) % 16) == 8) {
256+
if (insecure_randbits(4) == 8) {
259257
test.copy();
260258
}
261-
if (((r >> 15) % 32) == 18) {
259+
if (insecure_randbits(5) == 18) {
262260
test.move();
263261
}
264262
}

0 commit comments

Comments
 (0)