Skip to content

Commit 2208ca9

Browse files
Add separate tests for pipable bulk syntax
1 parent 558fc5e commit 2208ca9

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

tests/beman/execution/exec-bulk.test.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace {
1414
auto test_bulk() {
15-
auto b0 = test_std::just() | test_std::bulk(1, [](int) {});
15+
auto b0 = test_std::bulk(test_std::just(), 1, [](int) {});
1616

1717
static_assert(test_std::sender<decltype(b0)>);
1818
auto b0_env = test_std::get_env(b0);
@@ -25,7 +25,7 @@ auto test_bulk() {
2525

2626
int counter = 0;
2727

28-
auto b1 = test_std::just() | test_std::bulk(5, [&](int i) { counter += i; });
28+
auto b1 = test_std::bulk(test_std::just(), 5, [&](int i) { counter += i; });
2929

3030
static_assert(test_std::sender<decltype(b1)>);
3131
auto b1_env = test_std::get_env(b0);
@@ -43,9 +43,9 @@ auto test_bulk() {
4343

4444
std::vector<int> results(a.size(), 0);
4545

46-
auto b2 = test_std::just(a) | test_std::bulk(a.size(), [&](std::size_t index, const std::vector<int>& vec) {
47-
results[index] = vec[index] * b[index];
48-
});
46+
auto b2 = test_std::bulk(test_std::just(a), a.size(), [&](std::size_t index, const std::vector<int>& vec) {
47+
results[index] = vec[index] * b[index];
48+
});
4949
static_assert(test_std::sender<decltype(b2)>);
5050
auto b2_env = test_std::get_env(b2);
5151
auto b2_completions = test_std::get_completion_signatures(b2, b2_env);
@@ -65,7 +65,7 @@ auto test_bulk() {
6565
}
6666

6767
auto test_bulk_noexept() {
68-
auto b0 = test_std::just() | test_std::bulk(1, [](int) noexcept {});
68+
auto b0 = test_std::bulk(test_std::just(), 1, [](int) noexcept {});
6969
auto b0_env = test_std::get_env(b0);
7070
auto b0_completions = test_std::get_completion_signatures(b0, b0_env);
7171
static_assert(std::is_same_v<decltype(b0_completions),
@@ -75,7 +75,7 @@ auto test_bulk_noexept() {
7575

7676
int counter = 0;
7777

78-
auto b1 = test_std::just() | test_std::bulk(5, [&](int i) noexcept { counter += i; });
78+
auto b1 = test_std::bulk(test_std::just(), 5, [&](int i) noexcept { counter += i; });
7979

8080
static_assert(test_std::sender<decltype(b1)>);
8181
auto b1_env = test_std::get_env(b0);
@@ -87,6 +87,60 @@ auto test_bulk_noexept() {
8787
ASSERT(counter == 10);
8888
}
8989

90+
auto test_bulk_pipeable() {
91+
auto b0 = test_std::just() | test_std::bulk(1, [](int) {});
92+
93+
static_assert(test_std::sender<decltype(b0)>);
94+
auto b0_env = test_std::get_env(b0);
95+
auto b0_completions = test_std::get_completion_signatures(b0, b0_env);
96+
static_assert(
97+
std::is_same_v<decltype(b0_completions),
98+
beman::execution::completion_signatures<beman::execution::set_value_t(),
99+
beman::execution::set_error_t(std::exception_ptr)> >,
100+
"Completion signatures do not match!");
101+
102+
int counter = 0;
103+
104+
auto b1 = test_std::just() | test_std::bulk(5, [&](int i) { counter += i; });
105+
106+
static_assert(test_std::sender<decltype(b1)>);
107+
auto b1_env = test_std::get_env(b0);
108+
auto b1_completions = test_std::get_completion_signatures(b1, b1_env);
109+
static_assert(
110+
std::is_same_v<decltype(b1_completions),
111+
beman::execution::completion_signatures<beman::execution::set_value_t(),
112+
beman::execution::set_error_t(std::exception_ptr)> >,
113+
"Completion signatures do not match!");
114+
test_std::sync_wait(b1);
115+
ASSERT(counter == 10);
116+
117+
std::vector<int> a{1, 2, 3, 4, 5, 6, 7, 8};
118+
std::vector<int> b{9, 10, 11, 13, 14, 15, 16, 17};
119+
120+
std::vector<int> results(a.size(), 0);
121+
122+
auto b2 = test_std::just(a) | test_std::bulk(a.size(), [&](std::size_t index, const std::vector<int>& vec) {
123+
results[index] = vec[index] * b[index];
124+
});
125+
126+
static_assert(test_std::sender<decltype(b2)>);
127+
auto b2_env = test_std::get_env(b2);
128+
auto b2_completions = test_std::get_completion_signatures(b2, b2_env);
129+
static_assert(
130+
std::is_same_v<decltype(b2_completions),
131+
beman::execution::completion_signatures<beman::execution::set_value_t(std::vector<int>),
132+
beman::execution::set_error_t(std::exception_ptr)> >,
133+
"Completion signatures do not match!");
134+
test_std::sync_wait(b2);
135+
136+
// Expected results: element-wise multiplication of a and b
137+
std::vector<int> expected{9, 20, 33, 52, 70, 90, 112, 136};
138+
139+
for (size_t i = 0; i < results.size(); ++i) {
140+
ASSERT(results[i] == expected[i]);
141+
}
142+
}
143+
90144
} // namespace
91145

92146
TEST(exec_bulk) {

0 commit comments

Comments
 (0)