-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathExecTests.cpp
More file actions
59 lines (46 loc) · 1.81 KB
/
Copy pathExecTests.cpp
File metadata and controls
59 lines (46 loc) · 1.81 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <catch2/catch.hpp>
#include <rapidcheck/catch.h>
#include "rapidcheck/gen/Exec.h"
#include "util/Predictable.h"
#include "util/GenUtils.h"
using namespace rc;
using namespace rc::gen::detail;
using namespace rc::test;
TEST_CASE("gen::exec") {
prop("yields the same result as execRaw but without recipe",
[](const GenParams ¶ms) {
using Tuple = std::tuple<int, int, int>;
const auto callable = [](const FixedCountdown<2> &a) {
return std::make_tuple(
a.value, *genFixedCountdown(2), *genFixedCountdown(2));
};
const auto expected = gen::map(execRaw(callable),
[](const std::pair<Tuple, Recipe> &p) {
return p.first;
})(params.random, params.size);
const auto actual = gen::exec(callable)(params.random, params.size);
RC_ASSERT(actual == expected);
});
SECTION("works with non-copyable types") {
auto shrinkable =
gen::exec([=](NonCopyable nc) { return nc; })(Random(), 0);
REQUIRE(isArbitraryPredictable(shrinkable.value()));
}
prop("equivalent to monadic bind",
[] {
const auto a = *gen::inRange(0, 5);
const auto b = *gen::inRange(0, 5);
const auto execGen = gen::exec([=] {
int x1 = *genFixedCountdown(a);
int x2 = *genFixedCountdown(b);
return std::make_pair(x1, x2);
});
const auto bindGen = gen::mapcat(
genFixedCountdown(a),
[=](int x1) {
return gen::map(genFixedCountdown(b),
[=](int x2) { return std::make_pair(x1, x2); });
});
RC_ASSERT(execGen(Random(), 0) == bindGen(Random(), 0));
});
}