MCPcopy Create free account
hub / github.com/ConorWilliams/libfork / test

Function test

test/source/algorithm/map.cpp:50–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49template <typename Sch, typename F, typename Proj = std::identity>
50void test(Sch &&sch, F add_one, Proj proj = {}) {
51 //
52 int count = 0;
53
54 std::vector<int> v;
55
56 for (auto i = 0; i < 10'000; i++) {
57 v.push_back(i);
58 }
59
60 check(v, count++);
61
62 {
63 // Check grain = 1 case:
64 lf::sync_wait(sch, lf::map, v, v.begin(), add_one, proj);
65 check(v, count++);
66
67 // Check grain > 1 and n % grain == 0 case:
68
69 REQUIRE(v.size() % 100 == 0);
70 lf::sync_wait(sch, lf::map, v, v.begin(), 100, add_one);
71 check(v, count++);
72
73 // Check grain > 1 and n % grain != 0 case:
74 REQUIRE(v.size() % 300 != 0);
75 lf::sync_wait(sch, lf::map, v, v.begin(), 300, add_one);
76 check(v, count++);
77
78 // Check grain > size case:
79 REQUIRE(v.size() < 20'000);
80 lf::sync_wait(sch, lf::map, v, v.begin(), 20'000, add_one);
81 check(v, count++);
82 }
83
84#ifndef _MSC_VER
85
86 // ----------- Now with small inputs ----------- //
87
88 for (int i = 1; i < 4; ++i) {
89
90 std::vector<int> small{0, 0, 0};
91
92 lf::sync_wait(sch, lf::map, std::span(small.data(), 3), small.begin(), i, add_one);
93 REQUIRE(small == std::vector<int>{1, 1, 1});
94
95 lf::sync_wait(sch, lf::map, std::span(small.data(), 2), small.begin(), i, add_one);
96 REQUIRE(small == std::vector<int>{2, 2, 1});
97
98 lf::sync_wait(sch, lf::map, std::span(small.data(), 1), small.begin(), i, add_one);
99 REQUIRE(small == std::vector<int>{3, 2, 1});
100
101 lf::sync_wait(sch, lf::map, std::span(small.data(), 0), small.begin(), i, add_one);
102 REQUIRE(small == std::vector<int>{3, 2, 1});
103 }
104
105#endif
106}
107

Callers 1

map.cppFile · 0.70

Calls 4

sync_waitFunction · 0.85
checkFunction · 0.70
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected