1 #include "rxcpp/rx.hpp" 2 3 #include "rxcpp/rx-test.hpp" 4 #include "catch.hpp" 5 6 SCENARIO("first sample"){ 7 printf("//! [first sample]\n"); 8 auto values = rxcpp::observable<>::range(1, 3).first(); 9 values. 10 subscribe( __anon2ec4e2db0102(int v)11 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0202()12 [](){printf("OnCompleted\n");}); 13 printf("//! [first sample]\n"); 14 } 15 16 #if RXCPP_USE_EXCEPTIONS 17 SCENARIO("first empty sample"){ 18 printf("//! [first empty sample]\n"); 19 auto values = rxcpp::observable<>::empty<int>().first(); 20 values. 21 subscribe( __anon2ec4e2db0302(int v)22 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0402(std::exception_ptr ep)23 [](std::exception_ptr ep){ 24 try {std::rethrow_exception(ep);} 25 catch (const rxcpp::empty_error& ex) { 26 printf("OnError: %s\n", ex.what()); 27 } 28 }, __anon2ec4e2db0502()29 [](){printf("OnCompleted\n");}); 30 printf("//! [first empty sample]\n"); 31 } 32 #endif 33 34 SCENARIO("last sample"){ 35 printf("//! [last sample]\n"); 36 auto values = rxcpp::observable<>::range(1, 3).last(); 37 values. 38 subscribe( __anon2ec4e2db0602(int v)39 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0702()40 [](){printf("OnCompleted\n");}); 41 printf("//! [last sample]\n"); 42 } 43 44 #if RXCPP_USE_EXCEPTIONS 45 SCENARIO("last empty sample"){ 46 printf("//! [last empty sample]\n"); 47 auto values = rxcpp::observable<>::empty<int>().last(); 48 values. 49 subscribe( __anon2ec4e2db0802(int v)50 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0902(std::exception_ptr ep)51 [](std::exception_ptr ep){ 52 try {std::rethrow_exception(ep);} 53 catch (const rxcpp::empty_error& ex) { 54 printf("OnError: %s\n", ex.what()); 55 } 56 }, __anon2ec4e2db0a02()57 [](){printf("OnCompleted\n");}); 58 printf("//! [last empty sample]\n"); 59 } 60 #endif 61 62 SCENARIO("count sample"){ 63 printf("//! [count sample]\n"); 64 auto values = rxcpp::observable<>::range(1, 3).count(); 65 values. 66 subscribe( __anon2ec4e2db0b02(int v)67 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0c02()68 [](){printf("OnCompleted\n");}); 69 printf("//! [count sample]\n"); 70 } 71 72 #if RXCPP_USE_EXCEPTIONS 73 SCENARIO("count error sample"){ 74 printf("//! [count error sample]\n"); 75 auto values = rxcpp::observable<>::range(1, 3). 76 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 77 count(); 78 values. 79 subscribe( __anon2ec4e2db0d02(int v)80 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db0e02(std::exception_ptr ep)81 [](std::exception_ptr ep){ 82 try {std::rethrow_exception(ep);} 83 catch (const std::runtime_error& ex) { 84 printf("OnError: %s\n", ex.what()); 85 } 86 }, __anon2ec4e2db0f02()87 [](){printf("OnCompleted\n");}); 88 printf("//! [count error sample]\n"); 89 } 90 #endif 91 92 SCENARIO("sum sample"){ 93 printf("//! [sum sample]\n"); 94 auto values = rxcpp::observable<>::range(1, 3).sum(); 95 values. 96 subscribe( __anon2ec4e2db1002(int v)97 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db1102()98 [](){printf("OnCompleted\n");}); 99 printf("//! [sum sample]\n"); 100 } 101 102 #if RXCPP_USE_EXCEPTIONS 103 SCENARIO("sum empty sample"){ 104 printf("//! [sum empty sample]\n"); 105 auto values = rxcpp::observable<>::empty<int>().sum(); 106 values. 107 subscribe( __anon2ec4e2db1202(int v)108 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db1302(std::exception_ptr ep)109 [](std::exception_ptr ep){ 110 try {std::rethrow_exception(ep);} 111 catch (const rxcpp::empty_error& ex) { 112 printf("OnError: %s\n", ex.what()); 113 } 114 }, __anon2ec4e2db1402()115 [](){printf("OnCompleted\n");}); 116 printf("//! [sum empty sample]\n"); 117 } 118 #endif 119 120 SCENARIO("sum error sample"){ 121 printf("//! [sum error sample]\n"); 122 auto values = rxcpp::observable<>::range(1, 3). 123 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 124 sum(); 125 values. 126 subscribe( __anon2ec4e2db1502(int v)127 [](int v){printf("OnNext: %d\n", v);}, __anon2ec4e2db1602(std::exception_ptr ep)128 [](std::exception_ptr ep){ 129 try {std::rethrow_exception(ep);} 130 catch (const std::runtime_error& ex) { 131 printf("OnError: %s\n", ex.what()); 132 } 133 }, __anon2ec4e2db1702()134 [](){printf("OnCompleted\n");}); 135 printf("//! [sum error sample]\n"); 136 } 137 138 SCENARIO("average sample"){ 139 printf("//! [average sample]\n"); 140 auto values = rxcpp::observable<>::range(1, 4).average(); 141 values. 142 subscribe( __anon2ec4e2db1802(double v)143 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db1902()144 [](){printf("OnCompleted\n");}); 145 printf("//! [average sample]\n"); 146 } 147 148 #if RXCPP_USE_EXCEPTIONS 149 SCENARIO("average empty sample"){ 150 printf("//! [average empty sample]\n"); 151 auto values = rxcpp::observable<>::empty<int>().average(); 152 values. 153 subscribe( __anon2ec4e2db1a02(double v)154 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db1b02(std::exception_ptr ep)155 [](std::exception_ptr ep){ 156 try {std::rethrow_exception(ep);} 157 catch (const rxcpp::empty_error& ex) { 158 printf("OnError: %s\n", ex.what()); 159 } 160 }, __anon2ec4e2db1c02()161 [](){printf("OnCompleted\n");}); 162 printf("//! [average empty sample]\n"); 163 } 164 #endif 165 166 SCENARIO("average error sample"){ 167 printf("//! [average error sample]\n"); 168 auto values = rxcpp::observable<>::range(1, 4). 169 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 170 average(); 171 values. 172 subscribe( __anon2ec4e2db1d02(double v)173 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db1e02(std::exception_ptr ep)174 [](std::exception_ptr ep){ 175 try {std::rethrow_exception(ep);} 176 catch (const std::runtime_error& ex) { 177 printf("OnError: %s\n", ex.what()); 178 } 179 }, __anon2ec4e2db1f02()180 [](){printf("OnCompleted\n");}); 181 printf("//! [average error sample]\n"); 182 } 183 184 SCENARIO("max sample"){ 185 printf("//! [max sample]\n"); 186 auto values = rxcpp::observable<>::range(1, 4).max(); 187 values. 188 subscribe( __anon2ec4e2db2002(double v)189 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2102()190 [](){printf("OnCompleted\n");}); 191 printf("//! [max sample]\n"); 192 } 193 194 #if RXCPP_USE_EXCEPTIONS 195 SCENARIO("max empty sample"){ 196 printf("//! [max empty sample]\n"); 197 auto values = rxcpp::observable<>::empty<int>().max(); 198 values. 199 subscribe( __anon2ec4e2db2202(double v)200 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2302(std::exception_ptr ep)201 [](std::exception_ptr ep){ 202 try {std::rethrow_exception(ep);} 203 catch (const rxcpp::empty_error& ex) { 204 printf("OnError: %s\n", ex.what()); 205 } 206 }, __anon2ec4e2db2402()207 [](){printf("OnCompleted\n");}); 208 printf("//! [max empty sample]\n"); 209 } 210 #endif 211 212 SCENARIO("max error sample"){ 213 printf("//! [max error sample]\n"); 214 auto values = rxcpp::observable<>::range(1, 4). 215 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 216 max(); 217 values. 218 subscribe( __anon2ec4e2db2502(double v)219 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2602(std::exception_ptr ep)220 [](std::exception_ptr ep){ 221 try {std::rethrow_exception(ep);} 222 catch (const std::runtime_error& ex) { 223 printf("OnError: %s\n", ex.what()); 224 } 225 }, __anon2ec4e2db2702()226 [](){printf("OnCompleted\n");}); 227 printf("//! [max error sample]\n"); 228 } 229 230 SCENARIO("min sample"){ 231 printf("//! [min sample]\n"); 232 auto values = rxcpp::observable<>::range(1, 4).min(); 233 values. 234 subscribe( __anon2ec4e2db2802(double v)235 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2902()236 [](){printf("OnCompleted\n");}); 237 printf("//! [min sample]\n"); 238 } 239 240 #if RXCPP_USE_EXCEPTIONS 241 SCENARIO("min empty sample"){ 242 printf("//! [min empty sample]\n"); 243 auto values = rxcpp::observable<>::empty<int>().min(); 244 values. 245 subscribe( __anon2ec4e2db2a02(double v)246 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2b02(std::exception_ptr ep)247 [](std::exception_ptr ep){ 248 try {std::rethrow_exception(ep);} 249 catch (const rxcpp::empty_error& ex) { 250 printf("OnError: %s\n", ex.what()); 251 } 252 }, __anon2ec4e2db2c02()253 [](){printf("OnCompleted\n");}); 254 printf("//! [min empty sample]\n"); 255 } 256 #endif 257 258 SCENARIO("min error sample"){ 259 printf("//! [min error sample]\n"); 260 auto values = rxcpp::observable<>::range(1, 4). 261 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 262 min(); 263 values. 264 subscribe( __anon2ec4e2db2d02(double v)265 [](double v){printf("OnNext: %lf\n", v);}, __anon2ec4e2db2e02(std::exception_ptr ep)266 [](std::exception_ptr ep){ 267 try {std::rethrow_exception(ep);} 268 catch (const std::runtime_error& ex) { 269 printf("OnError: %s\n", ex.what()); 270 } 271 }, __anon2ec4e2db2f02()272 [](){printf("OnCompleted\n");}); 273 printf("//! [min error sample]\n"); 274 } 275