1 #include "../test.h" 2 #include "rxcpp/operators/rx-pairwise.hpp" 3 4 SCENARIO("pairwise - enough items to create pairs", "[pairwise][operators]") { 5 GIVEN("a cold observable of n ints") { 6 auto sc = rxsc::make_test(); 7 auto w = sc.create_worker(); 8 const rxsc::test::messages<int> on; 9 const rxsc::test::messages<std::tuple<int, int>> on_pairwise; 10 11 auto xs = sc.make_cold_observable({ 12 on.next(180, 1), 13 on.next(210, 2), 14 on.next(240, 3), 15 on.next(290, 4), 16 on.next(350, 5), 17 on.completed(400), 18 }); 19 20 WHEN("taken pairwise") { 21 22 auto res = w.start( 23 [xs]() { 24 return xs 25 | rxo::pairwise() 26 // forget type to workaround lambda deduction bug on msvc 2013 27 | rxo::as_dynamic(); 28 } 29 ); 30 31 THEN("the output contains n-1 tuples of ints"){ 32 auto delay = rxcpp::schedulers::test::subscribed_time; 33 auto required = rxu::to_vector({ 34 on_pairwise.next(210 + delay, std::make_tuple(1, 2)), 35 on_pairwise.next(240 + delay, std::make_tuple(2, 3)), 36 on_pairwise.next(290 + delay, std::make_tuple(3, 4)), 37 on_pairwise.next(350 + delay, std::make_tuple(4, 5)), 38 on_pairwise.completed(400 + delay) 39 }); 40 auto actual = res.get_observer().messages(); 41 REQUIRE(required == actual); 42 } 43 } 44 } 45 } 46 47 SCENARIO("pairwise - not enough items to create a pair", "[pairwise][operators]") { 48 GIVEN("a cold observable of 1 ints") { 49 auto sc = rxsc::make_test(); 50 auto w = sc.create_worker(); 51 const rxsc::test::messages<int> on; 52 const rxsc::test::messages<std::tuple<int, int>> on_pairwise; 53 54 auto xs = sc.make_cold_observable({ 55 on.next(180, 1), 56 on.completed(400), 57 }); 58 59 WHEN("taken pairwise") { 60 61 auto res = w.start( 62 [xs]() { 63 return xs 64 .pairwise() 65 // forget type to workaround lambda deduction bug on msvc 2013 66 .as_dynamic(); 67 } 68 ); 69 70 THEN("the output contains no tuples of ints"){ 71 auto delay = rxcpp::schedulers::test::subscribed_time; 72 auto required = rxu::to_vector({ 73 on_pairwise.completed(400 + delay) 74 }); 75 auto actual = res.get_observer().messages(); 76 REQUIRE(required == actual); 77 } 78 } 79 } 80 } 81