• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "rxcpp/rx.hpp"
2 
3 #include "rxcpp/rx-test.hpp"
4 #include "catch.hpp"
5 
6 SCENARIO("blocking first sample"){
7     printf("//! [blocking first sample]\n");
8     auto values = rxcpp::observable<>::range(1, 3).as_blocking();
9     auto first = values.first();
10     printf("first = %d\n", first);
11     printf("//! [blocking first sample]\n");
12 }
13 
14 SCENARIO("blocking first empty sample"){
15     printf("//! [blocking first empty sample]\n");
16     auto values = rxcpp::observable<>::empty<int>().as_blocking();
17     try {
18         auto first = values.first();
19         printf("first = %d\n", first);
20     } catch (const rxcpp::empty_error& ex) {
21         printf("Exception: %s\n", ex.what());
22     }
23     printf("//! [blocking first empty sample]\n");
24 }
25 
26 SCENARIO("blocking first error sample"){
27     printf("//! [blocking first error sample]\n");
28     auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source")).
29         as_blocking();
30     try {
31         auto first = values.first();
32         printf("first = %d\n", first);
33     } catch (const std::exception& ex) {
34         printf("Exception: %s\n", ex.what());
35     }
36     printf("//! [blocking first error sample]\n");
37 }
38 
39 SCENARIO("blocking last sample"){
40     printf("//! [blocking last sample]\n");
41     auto values = rxcpp::observable<>::range(1, 3).as_blocking();
42     auto last = values.last();
43     printf("last = %d\n", last);
44     printf("//! [blocking last sample]\n");
45 }
46 
47 SCENARIO("blocking last empty sample"){
48     printf("//! [blocking last empty sample]\n");
49     auto values = rxcpp::observable<>::empty<int>().as_blocking();
50     try {
51         auto last = values.last();
52         printf("last = %d\n", last);
53     } catch (const rxcpp::empty_error& ex) {
54         printf("Exception: %s\n", ex.what());
55     }
56     printf("//! [blocking last empty sample]\n");
57 }
58 
59 SCENARIO("blocking last error sample"){
60     printf("//! [blocking last error sample]\n");
61     auto values = rxcpp::observable<>::range(1, 3).
62         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
63         as_blocking();
64     try {
65         auto last = values.last();
66         printf("last = %d\n", last);
67     } catch (const std::exception& ex) {
68         printf("Exception: %s\n", ex.what());
69     }
70     printf("//! [blocking last error sample]\n");
71 }
72 
73 SCENARIO("blocking count sample"){
74     printf("//! [blocking count sample]\n");
75     auto values = rxcpp::observable<>::range(1, 3).as_blocking();
76     auto count = values.count();
77     printf("count = %d\n", count);
78     printf("//! [blocking count sample]\n");
79 }
80 
81 SCENARIO("blocking count error sample"){
82     printf("//! [blocking count error sample]\n");
83     auto values = rxcpp::observable<>::range(1, 3).
84         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
85         as_blocking();
86     try {
87         auto count = values.count();
88         printf("count = %d\n", count);
89     } catch (const std::exception& ex) {
90         printf("Exception: %s\n", ex.what());
91     }
92     printf("//! [blocking count error sample]\n");
93 }
94 
95 SCENARIO("blocking sum sample"){
96     printf("//! [blocking sum sample]\n");
97     auto values = rxcpp::observable<>::range(1, 3).as_blocking();
98     auto sum = values.sum();
99     printf("sum = %d\n", sum);
100     printf("//! [blocking sum sample]\n");
101 }
102 
103 SCENARIO("blocking sum empty sample"){
104     printf("//! [blocking sum empty sample]\n");
105     auto values = rxcpp::observable<>::empty<int>().as_blocking();
106     try {
107         auto sum = values.sum();
108         printf("sum = %d\n", sum);
109     } catch (const rxcpp::empty_error& ex) {
110         printf("Exception: %s\n", ex.what());
111     }
112     printf("//! [blocking sum empty sample]\n");
113 }
114 
115 SCENARIO("blocking sum error sample"){
116     printf("//! [blocking sum error sample]\n");
117     auto values = rxcpp::observable<>::range(1, 3).
118         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
119         as_blocking();
120     try {
121         auto sum = values.sum();
122         printf("sum = %d\n", sum);
123     } catch (const std::exception& ex) {
124         printf("Exception: %s\n", ex.what());
125     }
126     printf("//! [blocking sum error sample]\n");
127 }
128 
129 SCENARIO("blocking average sample"){
130     printf("//! [blocking average sample]\n");
131     auto values = rxcpp::observable<>::range(1, 4).as_blocking();
132     auto average = values.average();
133     printf("average = %lf\n", average);
134     printf("//! [blocking average sample]\n");
135 }
136 
137 SCENARIO("blocking average empty sample"){
138     printf("//! [blocking average empty sample]\n");
139     auto values = rxcpp::observable<>::empty<int>().as_blocking();
140     try {
141         auto average = values.average();
142         printf("average = %lf\n", average);
143     } catch (const rxcpp::empty_error& ex) {
144         printf("Exception: %s\n", ex.what());
145     }
146     printf("//! [blocking average empty sample]\n");
147 }
148 
149 SCENARIO("blocking average error sample"){
150     printf("//! [blocking average error sample]\n");
151     auto values = rxcpp::observable<>::range(1, 4).
152         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
153         as_blocking();
154     try {
155         auto average = values.average();
156         printf("average = %lf\n", average);
157     } catch (const std::exception& ex) {
158         printf("Exception: %s\n", ex.what());
159     }
160     printf("//! [blocking average error sample]\n");
161 }
162 
163 SCENARIO("blocking max sample"){
164     printf("//! [blocking max sample]\n");
165     auto values = rxcpp::observable<>::range(1, 4).as_blocking();
166     auto max = values.max();
167     printf("max = %d\n", max);
168     printf("//! [blocking max sample]\n");
169 }
170 
171 SCENARIO("blocking max empty sample"){
172     printf("//! [blocking max empty sample]\n");
173     auto values = rxcpp::observable<>::empty<int>().as_blocking();
174     try {
175         auto max = values.max();
176         printf("max = %d\n", max);
177     } catch (const rxcpp::empty_error& ex) {
178         printf("Exception: %s\n", ex.what());
179     }
180     printf("//! [blocking max empty sample]\n");
181 }
182 
183 SCENARIO("blocking max error sample"){
184     printf("//! [blocking max error sample]\n");
185     auto values = rxcpp::observable<>::range(1, 4).
186         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
187         as_blocking();
188     try {
189         auto max = values.max();
190         printf("max = %d\n", max);
191     } catch (const std::exception& ex) {
192         printf("Exception: %s\n", ex.what());
193     }
194     printf("//! [blocking max error sample]\n");
195 }
196 
197 SCENARIO("blocking min sample"){
198     printf("//! [blocking min sample]\n");
199     auto values = rxcpp::observable<>::range(1, 4).as_blocking();
200     auto min = values.min();
201     printf("min = %d\n", min);
202     printf("//! [blocking min sample]\n");
203 }
204 
205 SCENARIO("blocking min empty sample"){
206     printf("//! [blocking min empty sample]\n");
207     auto values = rxcpp::observable<>::empty<int>().as_blocking();
208     try {
209         auto min = values.min();
210         printf("min = %d\n", min);
211     } catch (const rxcpp::empty_error& ex) {
212         printf("Exception: %s\n", ex.what());
213     }
214     printf("//! [blocking min empty sample]\n");
215 }
216 
217 SCENARIO("blocking min error sample"){
218     printf("//! [blocking min error sample]\n");
219     auto values = rxcpp::observable<>::range(1, 4).
220         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
221         as_blocking();
222     try {
223         auto min = values.min();
224         printf("min = %d\n", min);
225     } catch (const std::exception& ex) {
226         printf("Exception: %s\n", ex.what());
227     }
228     printf("//! [blocking min error sample]\n");
229 }
230