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

Function test

test/source/algorithm/for_each.cpp:50–108  ·  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::for_each, v, 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::for_each, v, 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::for_each, v, 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::for_each, v, 20'000, add_one);
81 check(v, count++);
82 }
83
84#ifndef _MSC_VER
85
86 {
87 // ----------- Now with small inputs ----------- //
88
89 for (int i = 1; i < 4; ++i) {
90
91 std::vector<int> small{0, 0, 0};
92
93 lf::sync_wait(sch, lf::for_each, std::span(small.data(), 3), i, add_one);
94 REQUIRE(small == std::vector<int>{1, 1, 1});
95
96 lf::sync_wait(sch, lf::for_each, std::span(small.data(), 2), i, add_one);
97 REQUIRE(small == std::vector<int>{2, 2, 1});
98
99 lf::sync_wait(sch, lf::for_each, std::span(small.data(), 1), i, add_one);
100 REQUIRE(small == std::vector<int>{3, 2, 1});
101
102 lf::sync_wait(sch, lf::for_each, std::span(small.data(), 0), i, add_one);
103 REQUIRE(small == std::vector<int>{3, 2, 1});
104 }
105 }
106
107#endif

Callers 1

for_each.cppFile · 0.70

Calls 4

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

Tested by

no test coverage detected