-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.cpp
34 lines (30 loc) · 919 Bytes
/
test.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
#include <chrono>
#include <random>
#include "utils.hpp"
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
bool isEq(const datacount_t& a, const datacount_t& b) {
if (a.size() != b.size()) return false;
for (const auto& [k, v] : a)
if (!b.count(k) || a.at(k) != b.at(k)) return false;
return true;
}
TEST_CASE("datacount_t back & forth serialization", "[serialization]") {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> maxdatasets(0, 100);
std::uniform_int_distribution<size_t> val(0, std::numeric_limits<uint64_t>::max());
const int NTEST = 100;
for (int n = 0; n < NTEST; ++n) {
datacount_t d;
int S = maxdatasets(gen);
const int NLETTERS = maxdatasets(gen);
for (int i = 0; i < S; ++i) {
std::vector<uint64_t> counts(NLETTERS);
for (auto& v : counts) v = val(gen);
d[i] = counts;
}
auto str = serialize(d);
REQUIRE(isEq(d, deserialize(str)));
}
}