_test_pipeline.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Testing.h"
2 
3 #include <boost/pipeline.hpp>
4 #include <iostream>
5 
6 using namespace std;
7 using namespace boost::pipeline;
8 
9 void test_queue()
10 {
11  queue<int> q;
12  queue_front<int> qf(q);
13  queue_back<int> qb(q);
14 
15  Assert(qf.is_closed() == false);
16 
17  qb.push(1);
18  qb.push(2);
19  qb.push(3);
20 
21  int input = 0;
22 
23  qf.wait_pull(input);
24  Assert(input == 1);
25 
26  qf.wait_pull(input);
27  Assert(input == 2);
28 
29  qb.close();
30 
31  qf.wait_pull(input);
32  Assert(input == 3);
33 
34  Assert(qf.is_closed());
35 }
36 
37 
38 
39 
40 
41 void consume1(int x) {
42  cerr << "consume1(" << x << ")" << endl;
43 }
44 void consume2(queue_front<int>& qf) {
45  int i; qf.wait_pull(i);
46  cerr << "consume2(" << i << ")" << endl;
47 }
48 int consume3(int x) { return 0;
49  cerr << "consume3(" << x << ")" << endl;
50 }
51 int consume4(queue_front<int>& qf) {
52  int i; qf.wait_pull(i);
53  cerr << "consume4(" << i << ")" << endl;
54  return 0;
55 }
56 
57 
58 void test_to()
59 {
60  std::vector<int> input{0, 1, 2, 3};
61 
62  thread_pool pool(4);
63 
64  auto exec1 = (from(input) | consume1).run(pool);
65  auto exec2 = (from(input) | consume2).run(pool);
66  auto exec3 = (from(input) | to(consume3)).run(pool);
67  auto exec4 = (from(input) | to(consume4)).run(pool);
68 
69  exec1.wait();
70  exec2.wait();
71  exec3.wait();
72  exec4.wait();
73 }
74 
76 {
77  auto f_consume1 = std::function<void(int)>(consume1);
78  auto f_consume2 = std::function<void(queue_front<int>&)>(consume2);
79  auto f_consume3 = std::function<int(int)>(consume3);
80  auto f_consume4 = std::function<int(queue_front<int>&)>(consume4);
81 
82  std::vector<int> input{0, 1, 2, 3};
83 
84  thread_pool pool(4);
85 
86  auto exec1 = (from(input) | f_consume1).run(pool);
87  auto exec2 = (from(input) | f_consume2).run(pool);
88  auto exec3 = (from(input) | to(f_consume3)).run(pool);
89  auto exec4 = (from(input) | to(f_consume4)).run(pool);
90 
91  exec1.wait();
92  exec2.wait();
93  exec3.wait();
94  exec4.wait();
95 
96 }
97 
98 int main()
99 {
100  test_queue();
101  test_to();
102  test_tofunction();
103 
104 
105  return 0;
106 }
int consume3(int x)
void test_queue()
STL namespace.
#define Assert
Definition: Testing.h:7
void consume1(int x)
std::shared_ptr< spdlog::details::thread_pool > thread_pool()
Definition: async.h:83
int main()
static int input(void)
Definition: code.cpp:15695
void consume2(queue_front< int > &qf)
int consume4(queue_front< int > &qf)
void test_to()
list x
Definition: train.py:276
void test_tofunction()
QTextStream & endl(QTextStream &s)
unsigned int run