#include "rxcpp/rx.hpp" namespace rxu=rxcpp::util; namespace rxs=rxcpp::sources; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("buffer count partial window", "[buffer][operators]"){ GIVEN("1 hot observable of ints."){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; const rxsc::test::messages<std::vector<int>> v_on; auto xs = sc.make_hot_observable({ on.next(150, 1), on.next(210, 2), on.next(220, 3), on.next(230, 4), on.next(240, 5), on.completed(250) }); WHEN("group each int with the next 4 ints"){ auto res = w.start( [&]() { return xs .buffer(5) // forget type to workaround lambda deduction bug on msvc 2013
#include "rxcpp/rx.hpp" namespace rxu=rxcpp::util; 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(); } );
{ if (x < 2) return false; for (int i = 2; i <= x/2; ++i) { if (x % i == 0) return false; } return true; } } SCENARIO("filter stops on completion", "[filter][operators]"){ GIVEN("a test hot observable of ints"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; 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),
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("create stops on completion", "[create][sources]"){ GIVEN("a test cold observable of ints"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; long invoked = 0; WHEN("created"){ auto res = w.start( [&]() { return rx::observable<>::create<int>( [&](const rx::subscriber<int>& s){ invoked++; s.on_next(1); s.on_next(2); }) // forget type to workaround lambda deduction bug on msvc 2013 .as_dynamic(); } );
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxs=rxcpp::sources; namespace rxsc=rxcpp::schedulers; namespace rxn=rx::notifications; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("amb never 3", "[amb][join][operators]"){ GIVEN("1 cold observable with 3 hot observables of ints."){ 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_hot_observable({ on.next(100, 1) }); auto ys2 = sc.make_hot_observable({ on.next(110, 2) }); auto ys3 = sc.make_hot_observable({ on.next(120, 3) }); auto xs = sc.make_cold_observable({ o_on.next(100, ys1),
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("defer stops on completion", "[defer][sources]"){ GIVEN("a test cold observable of ints"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<long> on; long invoked = 0; rxu::detail::maybe<rx::test::testable_observable<long>> xs; WHEN("deferred"){ auto empty = rx::observable<>::empty<long>(); auto just = rx::observable<>::just(42); auto one = rx::observable<>::from(42); auto error = rx::observable<>::error<long>(std::exception_ptr()); auto runtimeerror = rx::observable<>::error<long>(std::runtime_error("runtime")); auto res = w.start( [&]() { return rx::observable<>::defer( [&](){ invoked++;
#include "rxcpp/rx.hpp" namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("zip never/never", "[zip][join][operators]"){ GIVEN("2 hot observables of ints."){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; auto n1 = sc.make_hot_observable({ on.next(150, 1) }); auto n2 = sc.make_hot_observable({ on.next(150, 1) }); WHEN("each int is combined with the latest from the other source"){ auto res = w.start( [&]() { return n1 .zip( [](int v2, int v1){ return v2 + v1; }, n2
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; namespace rxn=rx::notifications; #include "rxcpp/rx-test.hpp" #include "catch.hpp" 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),
#include "rxcpp/rx.hpp" namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("combine_latest return/return", "[combine_latest][join][operators]"){ GIVEN("2 hot observables of ints."){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; auto o1 = sc.make_hot_observable({ on.next(150, 1), on.next(215, 2), on.completed(230) }); auto o2 = sc.make_hot_observable({ on.next(150, 1), on.next(220, 3), on.completed(240) }); WHEN("each int is combined with the latest from the other source"){ auto res = w.start( [&]() { return o1 .combine_latest(
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxs=rxcpp::sources; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("replay basic", "[replay][multicast][subject][operators]"){ GIVEN("a test hot observable of ints"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; auto xs = sc.make_hot_observable({ on.next(110, 0), on.next(220, 1), on.next(280, 2), on.next(290, 3), on.next(340, 4), on.next(360, 5), on.next(370, 6), on.next(390, 7), on.next(410, 8), on.next(430, 9), on.next(450, 10), on.next(520, 11), on.next(560, 12), on.completed(600) });
#include "rxcpp/rx.hpp" namespace rx = rxcpp; namespace rxu = rxcpp::util; namespace rxs = rxcpp::sources; namespace rxsc = rxcpp::schedulers; #include "rxcpp/rx-test.hpp" namespace rxt = rxcpp::test; #include "catch.hpp" SCENARIO("window count, basic", "[window][operators]"){ GIVEN("1 hot observable of ints."){ 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 xs = sc.make_hot_observable({ on.next(100, 1), on.next(210, 2), on.next(240, 3), on.next(280, 4), on.next(320, 5), on.next(350, 6), on.next(380, 7), on.next(420, 8), on.next(470, 9), on.completed(600) });
#include "rxcpp/rx.hpp" namespace rx=rxcpp; namespace rxu=rxcpp::util; namespace rxsc=rxcpp::schedulers; #include "rxcpp/rx-test.hpp" #include "catch.hpp" SCENARIO("scope, cold observable", "[scope][sources]"){ GIVEN("a test cold observable of ints"){ auto sc = rxsc::make_test(); auto w = sc.create_worker(); const rxsc::test::messages<int> on; rxu::detail::maybe<rx::test::testable_observable<int>> xs; typedef rx::resource<std::vector<int>> resource; WHEN("created by scope"){ auto res = w.start( [&]() { return rx::observable<>:: scope( [&](){ return resource(rxu::to_vector({1, 2, 3, 4, 5})); }, [&](resource r){ auto msg = std::vector<rxsc::test::messages<int>::recorded_type>(); int time = 10; auto values = r.get();