Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesnicholson committed Dec 30, 2023
1 parent 1e2ff92 commit 5d3372d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tests/test_many_random_payloads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
#include <random>
#include <thread>

using std::atomic;
using std::generate;
using std::max;
using std::mt19937;
using std::none_of;
using std::thread;
using std::vector;

auto constexpr LEN{ 4u * 1024u * 1024u };

namespace {
std::atomic<int> s_iterations{ 250u };
atomic<int> s_iterations{ 250u };
}

TEST_CASE("many random payloads") {
auto const thread_proc{ [](unsigned seed) {
std::mt19937 mt{ seed }; // deterministic
mt19937 mt{ seed }; // deterministic
byte_vec_t src(LEN), dec(LEN), enc(COBS_ENCODE_MAX(LEN));

while (--s_iterations > 0) {
std::generate(src.begin(), src.end(), [&]() { return byte_t(mt()); });
generate(src.begin(), src.end(), [&]() { return byte_t(mt()); });
memset(src.data() + 1000, 0xAA, 256 * 10); // nonzero run

size_t enc_len{ 0u };
Expand All @@ -30,8 +38,7 @@ TEST_CASE("many random payloads") {

REQUIRE(enc_len >= LEN);
REQUIRE(enc_len <= COBS_ENCODE_MAX(LEN));
REQUIRE(
std::none_of(enc.data(), enc.data() + enc_len - 1, [](byte_t b) { return !b; }));
REQUIRE(none_of(enc.data(), enc.data() + enc_len - 1, [](byte_t b) { return !b; }));
REQUIRE(enc[enc_len - 1] == 0);

size_t dec_len{ 0u };
Expand All @@ -43,9 +50,8 @@ TEST_CASE("many random payloads") {
}
} };

std::vector<std::thread> threads;
for (auto i{ 0u }, n{ std::max(1u, std::thread::hardware_concurrency() - 1) }; i < n;
++i) {
vector<thread> threads;
for (auto i{ 0u }, n{ max(1u, thread::hardware_concurrency() - 1) }; i < n; ++i) {
threads.emplace_back(thread_proc, i);
}

Expand Down

0 comments on commit 5d3372d

Please sign in to comment.