| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6d36b0 commit 2025fc3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,10 +10,12 @@ | |||
| 10 | 10 | ||
| 11 | 11 | #include <queue> | |
| 12 | 12 | #include <string> | |
| 13 | + #include <tuple> | ||
| 13 | 14 | ||
| 14 | 15 | #include "react/Domain.h" | |
| 15 | 16 | #include "react/Signal.h" | |
| 16 | 17 | #include "react/Event.h" | |
| 18 | + #include "react/Observer.h" | ||
| 17 | 19 | #include "react/Algorithm.h" | |
| 18 | 20 | ||
| 19 | 21 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -22,6 +24,12 @@ namespace { | |||
| 22 | 24 | using namespace react; | |
| 23 | 25 | using namespace std; | |
| 24 | 26 | ||
| 27 | + template <typename T> | ||
| 28 | + struct Incrementer { T operator()(T v) const { return v+1; } }; | ||
| 29 | + | ||
| 30 | + template <typename T> | ||
| 31 | + struct Decrementer { T operator()(T v) const { return v-1; } }; | ||
| 32 | + | ||
| 25 | 33 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 26 | 34 | /// EventStreamTest fixture | |
| 27 | 35 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -173,7 +181,7 @@ TYPED_TEST_P(OperationsTest, Pulse1) | |||
| 173 | 181 | ||
| 174 | 182 | vector<int> results; | |
| 175 | 183 | ||
| 176 | - auto p = Pulse(target, trigger); | ||
| 184 | + auto p = Pulse(trigger, target); | ||
| 177 | 185 | ||
| 178 | 186 | Observe(p, [&] (int v) { | |
| 179 | 187 | results.push_back(v); | |
@@ -198,7 +206,7 @@ TYPED_TEST_P(OperationsTest, Snapshot1) | |||
| 198 | 206 | auto trigger = MyDomain::MakeEventSource(); | |
| 199 | 207 | auto target = MyDomain::MakeVar(10); | |
| 200 | 208 | ||
| 201 | - auto snap = Snapshot(target, trigger); | ||
| 209 | + auto snap = Snapshot(trigger, target); | ||
| 202 | 210 | ||
| 203 | 211 | target <<= 10; | |
| 204 | 212 | trigger.Emit(); | |
@@ -261,6 +269,76 @@ TYPED_TEST_P(OperationsTest, IterateByRef1) | |||
| 261 | 269 | ASSERT_EQ(x()[i], 123); | |
| 262 | 270 | } | |
| 263 | 271 | ||
| 272 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 273 | + /// GenerateEvents test | ||
| 274 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 275 | + TYPED_TEST_P(OperationsTest, GenerateEvents1) | ||
| 276 | + { | ||
| 277 | + auto in1 = MyDomain::MakeVar(1); | ||
| 278 | + auto in2 = MyDomain::MakeVar(1); | ||
| 279 | + | ||
| 280 | + auto sum = in1 + in2; | ||
| 281 | + auto prod = in1 * in2; | ||
| 282 | + auto diff = in1 - in2; | ||
| 283 | + | ||
| 284 | + auto src1 = MyDomain::MakeEventSource(); | ||
| 285 | + auto src2 = MyDomain::MakeEventSource<int>(); | ||
| 286 | + | ||
| 287 | + auto out1 = GenerateEvents(src1, [] (int sum, int prod, int diff) { | ||
| 288 | + return make_tuple(sum, prod, diff); | ||
| 289 | + }, sum, prod, diff); | ||
| 290 | + | ||
| 291 | + auto out2 = GenerateEvents(src2, [] (int e, int sum, int prod, int diff) { | ||
| 292 | + return make_tuple(e, sum, prod, diff); | ||
| 293 | + }, sum, prod, diff); | ||
| 294 | + | ||
| 295 | + Observe(out1, [] (const tuple<int,int,int>& t) { | ||
| 296 | + ASSERT_EQ(get<0>(t), 33); | ||
| 297 | + ASSERT_EQ(get<1>(t), 242); | ||
| 298 | + ASSERT_EQ(get<2>(t), 11); | ||
| 299 | + | ||
| 300 | + DetachThisObserver(); | ||
| 301 | + }); | ||
| 302 | + | ||
| 303 | + Observe(out2, [] (const tuple<int,int,int,int>& t) { | ||
| 304 | + ASSERT_EQ(get<0>(t), 42); | ||
| 305 | + ASSERT_EQ(get<1>(t), 33); | ||
| 306 | + ASSERT_EQ(get<2>(t), 242); | ||
| 307 | + ASSERT_EQ(get<3>(t), 11); | ||
| 308 | + | ||
| 309 | + DetachThisObserver(); | ||
| 310 | + }); | ||
| 311 | + | ||
| 312 | + in1 <<= 22; | ||
| 313 | + in2 <<= 11; | ||
| 314 | + | ||
| 315 | + src1.Emit(); | ||
| 316 | + src2.Emit(42); | ||
| 317 | + | ||
| 318 | + Observe(out1, [] (const tuple<int,int,int>& t) { | ||
| 319 | + ASSERT_EQ(get<0>(t), 3300); | ||
| 320 | + ASSERT_EQ(get<1>(t), 24200); | ||
| 321 | + ASSERT_EQ(get<2>(t), 1100); | ||
| 322 | + | ||
| 323 | + DetachThisObserver(); | ||
| 324 | + }); | ||
| 325 | + | ||
| 326 | + Observe(out2, [] (const tuple<int,int,int,int>& t) { | ||
| 327 | + ASSERT_EQ(get<0>(t), 420); | ||
| 328 | + ASSERT_EQ(get<1>(t), 3300); | ||
| 329 | + ASSERT_EQ(get<2>(t), 24200); | ||
| 330 | + ASSERT_EQ(get<3>(t), 1100); | ||
| 331 | + | ||
| 332 | + DetachThisObserver(); | ||
| 333 | + }); | ||
| 334 | + | ||
| 335 | + in1 <<= 220; | ||
| 336 | + in2 <<= 110; | ||
| 337 | + | ||
| 338 | + src1.Emit(); | ||
| 339 | + src2.Emit(420); | ||
| 340 | + } | ||
| 341 | + | ||
| 264 | 342 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 265 | 343 | REGISTER_TYPED_TEST_CASE_P | |
| 266 | 344 | ( | |
@@ -273,7 +351,8 @@ REGISTER_TYPED_TEST_CASE_P | |||
| 273 | 351 | Pulse1, | |
| 274 | 352 | Snapshot1, | |
| 275 | 353 | FoldByRef1, | |
| 276 | - IterateByRef1 | ||
| 354 | + IterateByRef1, | ||
| 355 | + GenerateEvents1 | ||
| 277 | 356 | ); | |
| 278 | 357 | ||
| 279 | 358 | } // ~namespace | |
| Back | FazBrowse Home | New Git URL |
0 commit comments