aboutsummaryrefslogtreecommitdiff
path: root/src/test/prevector_tests.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-05-23 16:14:51 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-06-07 11:35:16 -0700
commit2ada67852174a76753080d65a7adbe27241a9caa (patch)
tree37bca3fc3117f89912559ddb755ef2c23261e340 /src/test/prevector_tests.cpp
parent5f0b04eedc5bbdb9319c9f1f1a6c599337f5bbe3 (diff)
downloadbitcoin-2ada67852174a76753080d65a7adbe27241a9caa.tar.xz
Use randbits instead of ad-hoc emulation in prevector tests
Diffstat (limited to 'src/test/prevector_tests.cpp')
-rw-r--r--src/test/prevector_tests.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp
index d951a6c3c2..674221e009 100644
--- a/src/test/prevector_tests.cpp
+++ b/src/test/prevector_tests.cpp
@@ -198,32 +198,31 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
for (int j = 0; j < 64; j++) {
prevector_tester<8, int> test;
for (int i = 0; i < 2048; i++) {
- int r = insecure_rand();
- if ((r % 4) == 0) {
+ if (insecure_randbits(2) == 0) {
test.insert(insecure_randrange(test.size() + 1), insecure_rand());
}
- if (test.size() > 0 && ((r >> 2) % 4) == 1) {
+ if (test.size() > 0 && insecure_randbits(2) == 1) {
test.erase(insecure_randrange(test.size()));
}
- if (((r >> 4) % 8) == 2) {
+ if (insecure_randbits(3) == 2) {
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (insecure_randrange(5)) - 2));
test.resize(new_size);
}
- if (((r >> 7) % 8) == 3) {
+ if (insecure_randbits(3) == 3) {
test.insert(insecure_randrange(test.size() + 1), 1 + insecure_randrange(2), insecure_rand());
}
- if (((r >> 10) % 8) == 4) {
+ if (insecure_randbits(3) == 4) {
int del = std::min<int>(test.size(), 1 + (insecure_randrange(2)));
int beg = insecure_randrange(test.size() + 1 - del);
test.erase(beg, beg + del);
}
- if (((r >> 13) % 16) == 5) {
+ if (insecure_randbits(4) == 5) {
test.push_back(insecure_rand());
}
- if (test.size() > 0 && ((r >> 17) % 16) == 6) {
+ if (test.size() > 0 && insecure_randbits(4) == 6) {
test.pop_back();
}
- if (((r >> 21) % 32) == 7) {
+ if (insecure_randbits(5) == 7) {
int values[4];
int num = 1 + (insecure_randrange(4));
for (int k = 0; k < num; k++) {
@@ -231,34 +230,33 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
}
test.insert_range(insecure_randrange(test.size() + 1), values, values + num);
}
- if (((r >> 26) % 32) == 8) {
+ if (insecure_randbits(5) == 8) {
int del = std::min<int>(test.size(), 1 + (insecure_randrange(4)));
int beg = insecure_randrange(test.size() + 1 - del);
test.erase(beg, beg + del);
}
- r = insecure_rand();
- if (r % 32 == 9) {
+ if (insecure_randbits(5) == 9) {
test.reserve(insecure_randrange(32));
}
- if ((r >> 5) % 64 == 10) {
+ if (insecure_randbits(6) == 10) {
test.shrink_to_fit();
}
if (test.size() > 0) {
test.update(insecure_randrange(test.size()), insecure_rand());
}
- if (((r >> 11) % 1024) == 11) {
+ if (insecure_randbits(10) == 11) {
test.clear();
}
- if (((r >> 21) % 512) == 12) {
+ if (insecure_randbits(9) == 12) {
test.assign(insecure_randrange(32), insecure_rand());
}
- if (((r >> 15) % 8) == 3) {
+ if (insecure_randbits(3) == 3) {
test.swap();
}
- if (((r >> 15) % 16) == 8) {
+ if (insecure_randbits(4) == 8) {
test.copy();
}
- if (((r >> 15) % 32) == 18) {
+ if (insecure_randbits(5) == 18) {
test.move();
}
}