summaryrefslogtreecommitdiff
path: root/Rx/v2/test/operators/reduce.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Rx/v2/test/operators/reduce.cpp')
-rw-r--r--Rx/v2/test/operators/reduce.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/Rx/v2/test/operators/reduce.cpp b/Rx/v2/test/operators/reduce.cpp
index 819f86c..33a0644 100644
--- a/Rx/v2/test/operators/reduce.cpp
+++ b/Rx/v2/test/operators/reduce.cpp
@@ -56,6 +56,61 @@ SCENARIO("reduce some data with seed", "[reduce][operators]"){
}
}
+SCENARIO("accumulate some data with seed", "[accumulate][reduce][operators]"){
+ GIVEN("a test hot observable of ints"){
+ auto sc = rxsc::make_test();
+ auto w = sc.create_worker();
+ const rxsc::test::messages<int> on;
+
+ int seed = 42;
+
+ auto xs = sc.make_hot_observable({
+ on.next(150, 1),
+ on.next(210, 0),
+ on.next(220, 1),
+ on.next(230, 2),
+ on.next(240, 3),
+ on.next(250, 4),
+ on.completed(260)
+ });
+
+ WHEN("mapped to ints that are one larger"){
+
+ auto res = w.start(
+ [&]() {
+ return xs
+ .accumulate(seed,
+ [](int sum, int x) {
+ return sum + x;
+ },
+ [](int sum) {
+ return sum * 5;
+ })
+ // forget type to workaround lambda deduction bug on msvc 2013
+ .as_dynamic();
+ }
+ );
+
+ THEN("the output stops on completion"){
+ auto required = rxu::to_vector({
+ on.next(260, (seed + 0 + 1 + 2 + 3 + 4) * 5),
+ on.completed(260)
+ });
+ auto actual = res.get_observer().messages();
+ REQUIRE(required == actual);
+ }
+
+ THEN("there was one subscription and one unsubscription"){
+ auto required = rxu::to_vector({
+ on.subscribe(200, 260)
+ });
+ auto actual = xs.subscriptions();
+ REQUIRE(required == actual);
+ }
+ }
+ }
+}
+
SCENARIO("average some data", "[reduce][average][operators]"){
GIVEN("a test hot observable of ints"){
auto sc = rxsc::make_test();