Changeset View
Changeset View
Standalone View
Standalone View
src/test/prevector_tests.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | void move() { | ||||
pre_vector_alt.clear(); | pre_vector_alt.clear(); | ||||
} | } | ||||
void copy() { | void copy() { | ||||
real_vector = real_vector_alt; | real_vector = real_vector_alt; | ||||
pre_vector = pre_vector_alt; | pre_vector = pre_vector_alt; | ||||
} | } | ||||
void resize_uninitialized(realtype values) { | |||||
size_t r = values.size(); | |||||
size_t s = real_vector.size() / 2; | |||||
if (real_vector.capacity() < s + r) { | |||||
real_vector.reserve(s + r); | |||||
} | |||||
real_vector.resize(s); | |||||
pre_vector.resize_uninitialized(s); | |||||
for (auto v : values) { | |||||
real_vector.push_back(v); | |||||
} | |||||
auto p = pre_vector.size(); | |||||
pre_vector.resize_uninitialized(p + r); | |||||
for (auto v : values) { | |||||
pre_vector[p] = v; | |||||
++p; | |||||
} | |||||
test(); | |||||
} | |||||
~prevector_tester() { | ~prevector_tester() { | ||||
BOOST_CHECK_MESSAGE(passed, "insecure_rand: " + rand_seed.ToString()); | BOOST_CHECK_MESSAGE(passed, "insecure_rand: " + rand_seed.ToString()); | ||||
} | } | ||||
prevector_tester() { | prevector_tester() { | ||||
SeedInsecureRand(); | SeedInsecureRand(); | ||||
rand_seed = InsecureRand256(); | rand_seed = InsecureRand256(); | ||||
rand_cache = FastRandomContext(rand_seed); | rand_cache = FastRandomContext(rand_seed); | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for (int j = 0; j < 64; j++) { | ||||
test.swap(); | test.swap(); | ||||
} | } | ||||
if (InsecureRandBits(4) == 8) { | if (InsecureRandBits(4) == 8) { | ||||
test.copy(); | test.copy(); | ||||
} | } | ||||
if (InsecureRandBits(5) == 18) { | if (InsecureRandBits(5) == 18) { | ||||
test.move(); | test.move(); | ||||
} | } | ||||
if (InsecureRandBits(5) == 19) { | |||||
unsigned int num = 1 + (InsecureRandBits(4)); | |||||
std::vector<int> values(num); | |||||
for (auto &v : values) { | |||||
v = InsecureRand32(); | |||||
} | |||||
test.resize_uninitialized(values); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |