namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("repeat, basic test", "[repeat][operators]"){ GIVEN("cold observable of 3 ints."){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; auto xs = sc.make_cold_observable({ on.on_next(100, 1), on.on_next(150, 2), on.on_next(200, 3), on.on_completed(250) }); WHEN("infinite repeat is launched"){ auto res = w.start( [&]() { return xs .repeat() // forget type to workaround lambda deduction bug on msvc 2013 .as_dynamic(); } ); THEN("the output contains 3 sets of ints"){ auto required = rxu::to_vector({
long invoked = 0; auto xs = sc.make_hot_observable({ on.on_next(110, 1), on.on_next(180, 2), on.on_next(230, 3), on.on_next(270, 4), on.on_next(340, 5), on.on_next(380, 6), on.on_next(390, 7), on.on_next(450, 8), on.on_next(470, 9), on.on_next(560, 10), on.on_next(580, 11), on.on_completed(600), on.on_next(610, 12), on.on_error(620, std::runtime_error("error in unsubscribed stream")), on.on_completed(630) }); WHEN("filtered to ints that are primes"){ auto res = w.start( [&xs, &invoked]() { #if 0 && RXCPP_USE_OBSERVABLE_MEMBERS return xs .filter([&invoked](int x) { invoked++; return IsPrime(x); }) // forget type to workaround lambda deduction bug on msvc 2013
SCENARIO("switch_on_next - some changes", "[switch_on_next][operators]"){ GIVEN("a source"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; const rxsc::test::messages<rx::observable<int>> o_on; auto ys1 = sc.make_cold_observable({ on.on_next(10, 101), on.on_next(20, 102), on.on_next(110, 103), on.on_next(120, 104), on.on_next(210, 105), on.on_next(220, 106), on.on_completed(230) }); auto ys2 = sc.make_cold_observable({ on.on_next(10, 201), on.on_next(20, 202), on.on_next(30, 203), on.on_next(40, 204), on.on_completed(50) }); auto ys3 = sc.make_cold_observable({ on.on_next(10, 301), on.on_next(20, 302), on.on_next(30, 303), on.on_next(40, 304),