-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathFrequencyMapTests.cpp
More file actions
42 lines (33 loc) · 1.11 KB
/
Copy pathFrequencyMapTests.cpp
File metadata and controls
42 lines (33 loc) · 1.11 KB
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
35
36
37
38
39
40
41
42
#include <catch2/catch.hpp>
#include <rapidcheck/catch.h>
#include <numeric>
#include "rapidcheck/detail/FrequencyMap.h"
using namespace rc;
using namespace rc::detail;
TEST_CASE("FrequencyMap") {
static const auto genFrequencies = gen::nonEmpty(
gen::container<std::vector<std::size_t>>(gen::inRange(1, 10000)));
SECTION("sum") {
prop("returns sum of frequencies",
[] {
const auto frequencies = *genFrequencies;
const auto expected = std::accumulate(
begin(frequencies), end(frequencies), std::size_t(0));
RC_ASSERT(FrequencyMap(frequencies).sum() == expected);
});
}
SECTION("lookup") {
prop("equal to naive implementation",
[] {
const auto frequencies = *genFrequencies;
FrequencyMap map(frequencies);
const auto x = *gen::inRange<std::size_t>(0, map.sum());
std::size_t total = 0;
std::size_t i = 0;
for (i = 0; (total + frequencies[i]) <= x; i++) {
total += frequencies[i];
}
RC_ASSERT(map.lookup(x) == i);
});
}
}