Ejemplo n.º 1
0
#include "../test.h"

SCENARIO("sample with time, error", "[sample_with_time][operators]"){
    GIVEN("1 hot observable of ints."){
        auto sc = rxsc::make_test();
        auto so = rx::synchronize_in_one_worker(sc);
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;

        std::runtime_error ex("sample_with_time on_error from source");

        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.error(600, ex)
        });
        WHEN("group ints on intersecting intervals"){
            using namespace std::chrono;

            auto res = w.start(
                [&]() {
                    return xs
                        .sample_with_time(milliseconds(100), so)
                        .as_dynamic();
Ejemplo n.º 2
0
#include "../test.h"
#include <rxcpp/operators/rx-finally.hpp>

SCENARIO("finally - never", "[finally][operators]"){
    GIVEN("a source"){
        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.next(150, 1)
        });

        WHEN("finally action is set"){

            auto res = w.start(
                [xs, &invoked]() {
                    return xs
                        | rxo::finally([&invoked]() {
                             ++invoked;
                        })
                        // forget type to workaround lambda deduction bug on msvc 2013
                        | rxo::as_dynamic();
                }
            );

            THEN("finally called once"){
                REQUIRE(1 == invoked);
            }
Ejemplo n.º 3
0
#include "../test.h"
#include <rxcpp/operators/rx-take_last.hpp>

SCENARIO("take last 0", "[take_last][operators]") {
    GIVEN("a source") {
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> 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("0 last values are taken") {

            auto res = w.start(
            [xs]() {
                return xs
                       | rxo::take_last(0)
                       // forget type to workaround lambda deduction bug on msvc 2013
                       | rxo::as_dynamic();
            }
                       );

            THEN("the output only contains the completion event") {
                auto required = rxu::to_vector({
Ejemplo n.º 4
0
#include "../test.h"

SCENARIO("tap stops on completion", "[tap][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.next(180, 1),
            on.next(210, 2),
            on.next(240, 3),
            on.next(290, 4),
            on.next(350, 5),
            on.completed(400),
            on.next(410, -1),
            on.completed(420),
            on.error(430, std::runtime_error("error on unsubscribed stream"))
        });

        WHEN("on_next is tapped") {

            auto res = w.start(
            [xs, &invoked]() {
                return xs
                .tap([&invoked](int) {
                    invoked++;
                })
                // forget type to workaround lambda deduction bug on msvc 2013
                .as_dynamic();
Ejemplo n.º 5
0
#include "../test.h"
#include <rxcpp/operators/rx-start_with.hpp>

SCENARIO("start_with - source never emits or completes", "[start_with][operators]"){
    GIVEN("a source"){
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;

        auto xs = sc.make_hot_observable({
            on.next(150, 1)
        });

        WHEN("start_with one value"){

            auto res = w.start(
                [xs]() {
                    return xs
                        | rxo::start_with(1)
                        // forget type to workaround lambda deduction bug on msvc 2013
                        | rxo::as_dynamic();
                }
            );

            THEN("the output contains start_with value"){
                auto required = rxu::to_vector({
                    on.next(200, 1)
                });
                auto actual = res.get_observer().messages();
                REQUIRE(required == actual);
            }
Ejemplo n.º 6
0
#include "../test.h"
#include "rxcpp/operators/rx-sequence_equal.hpp"

SCENARIO("sequence_equal - source never emits", "[sequence_equal][operators]"){
    GIVEN("two sources"){
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;

        auto xs = sc.make_hot_observable({
            on.next(150, 1)
        });

        auto ys = sc.make_hot_observable({
            on.next(150, 1),
            on.next(200, 2),
            on.next(300, 3),
            on.next(400, 4),
            on.next(500, 5),
            on.completed(600)
        });

        WHEN("two observables are checked for equality"){

            auto res = w.start(
                [xs, ys]() {
                    return xs
                            | rxo::sequence_equal(ys)
                            | rxo::as_dynamic(); // forget type to workaround lambda deduction bug on msvc 2013
                }
            );
Ejemplo n.º 7
0
#include "../test.h"

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.next(100, 1),
            on.next(150, 2),
            on.next(200, 3),
            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({
                    on.next(300, 1),
                    on.next(350, 2),
                    on.next(400, 3),
Ejemplo n.º 8
0
#include "../test.h"
#include <rxcpp/operators/rx-map.hpp>
#include <rxcpp/operators/rx-merge.hpp>
#include <rxcpp/operators/rx-window_toggle.hpp>

SCENARIO("window toggle, basic", "[window_toggle][operators]"){
    GIVEN("1 hot observable of ints and hot observable of opens."){
        auto sc = rxsc::make_test();
        auto so = rx::synchronize_in_one_worker(sc);
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;
        const rxsc::test::messages<std::string> o_on;

        auto xs = sc.make_hot_observable({
            on.next(90, 1),
            on.next(180, 2),
            on.next(250, 3),
            on.next(260, 4),
            on.next(310, 5),
            on.next(340, 6),
            on.next(410, 7),
            on.next(420, 8),
            on.next(470, 9),
            on.next(550, 10),
            on.completed(590)
        });

        auto ys = sc.make_hot_observable({
            on.next(255, 50),
            on.next(330, 100),
            on.next(350, 50),
Ejemplo n.º 9
0
#include "../test.h"

SCENARIO("pairwise", "[pairwise][operators]") {
    GIVEN("a cold observable of n ints") {
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;
        const rxsc::test::messages<std::tuple<int, int>> on_pairwise;
        long invoked = 0;

        auto xs = sc.make_cold_observable({
            on.next(180, 1),
            on.next(210, 2),
            on.next(240, 3),
            on.next(290, 4),
            on.next(350, 5),
            on.completed(400),
        });

        WHEN("taken pairwise") {

            auto res = w.start(
                [xs, &invoked]() {
                    return xs
                        .pairwise()
                        // forget type to workaround lambda deduction bug on msvc 2013
                        .as_dynamic();
                }
            );

            THEN("the output contains n-1 tuples of ints"){
Ejemplo n.º 10
0
#include "../test.h"
#include "rxcpp/operators/rx-amb.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),
            o_on.next(100, ys2),
            o_on.next(100, ys3),
            o_on.completed(200)
        });

        WHEN("the first observable is selected to produce ints"){
Ejemplo n.º 11
0
#include "../test.h"

SCENARIO("contains emits true if an item satisfies the given condition", "[contains][operators]"){
    GIVEN("a source") {
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;
        const rxsc::test::messages<bool> on_contains;

        auto xs = sc.make_hot_observable({
            on.next(150, 1),
            on.next(210, 2),
            on.completed(250)
        });

        WHEN("invoked with a predicate"){

            auto res = w.start(
                [xs]() {
                    return xs
                        .contains(2)
                        .as_dynamic(); // forget type to workaround lambda deduction bug on msvc 2013
                }
            );

            THEN("the output only contains true"){
                auto required = rxu::to_vector({
                    on_contains.next(210, true),
                    on_contains.completed(210)
                });
                auto actual = res.get_observer().messages();
Ejemplo n.º 12
0
#include "../test.h"

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
                        .as_dynamic();
                }
            );

            THEN("the output contains groups of ints"){
                auto required = rxu::to_vector({
Ejemplo n.º 13
0
#include "../test.h"
#include <rxcpp/operators/rx-all.hpp>

SCENARIO("is_empty emits false if the source observable is not empty", "[is_empty][operators]") {
    GIVEN("a source") {
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;
        const rxsc::test::messages<bool> on_is_empty;

        auto xs = sc.make_hot_observable({
            on.next(150, 1),
            on.next(210, 10),
            on.next(220, 20),
            on.completed(250)
        });

        WHEN("is_empty is invoked") {

            auto res = w.start(
                [xs]() {
                    return xs
                        | rxo::is_empty()
                        | rxo::as_dynamic(); // forget type to workaround lambda deduction bug on msvc 2013
                }
            );

            THEN("the output only contains true") {
                auto required = rxu::to_vector({
                    on_is_empty.next(210, false),
                    on_is_empty.completed(210)
Ejemplo n.º 14
0
#include "../test.h"
#include <rxcpp/operators/rx-any.hpp>

SCENARIO("any emits true if an item satisfies the given condition", "[any][operators]"){
    GIVEN("a source") {
        auto sc = rxsc::make_test();
        auto w = sc.create_worker();
        const rxsc::test::messages<int> on;
        const rxsc::test::messages<bool> on_any;

        auto xs = sc.make_hot_observable({
            on.next(150, 1),
            on.next(210, 2),
            on.completed(250)
        });

        WHEN("invoked with a predicate"){

            auto res = w.start(
                [xs]() {
                    return xs
                        | rxo::any([](int n) { return n == 2; })
                        | rxo::as_dynamic(); // forget type to workaround lambda deduction bug on msvc 2013
                }
            );

            THEN("the output only contains true"){
                auto required = rxu::to_vector({
                    on_any.next(210, true),
                    on_any.completed(210)
                });