FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added testcase for GenerateEvents1. · lineCode/cpp.react@2025fc3 · GitHub

Commit 2025fc3

Browse files
committed
Added testcase for GenerateEvents1.
1 parent c6d36b0 commit 2025fc3

1 file changed

Lines changed: 82 additions & 3 deletions

File tree

‎src/test/OperationsTest.h‎

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
#include <queue>
1212
#include <string>
13+
#include <tuple>
1314

1415
#include "react/Domain.h"
1516
#include "react/Signal.h"
1617
#include "react/Event.h"
18+
#include "react/Observer.h"
1719
#include "react/Algorithm.h"
1820

1921
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -22,6 +24,12 @@ namespace {
2224
using namespace react;
2325
using namespace std;
2426

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+
2533
///////////////////////////////////////////////////////////////////////////////////////////////////
2634
/// EventStreamTest fixture
2735
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -173,7 +181,7 @@ TYPED_TEST_P(OperationsTest, Pulse1)
173181

174182
vector<int> results;
175183

176-
auto p = Pulse(target, trigger);
184+
auto p = Pulse(trigger, target);
177185

178186
Observe(p, [&] (int v) {
179187
results.push_back(v);
@@ -198,7 +206,7 @@ TYPED_TEST_P(OperationsTest, Snapshot1)
198206
auto trigger = MyDomain::MakeEventSource();
199207
auto target = MyDomain::MakeVar(10);
200208

201-
auto snap = Snapshot(target, trigger);
209+
auto snap = Snapshot(trigger, target);
202210

203211
target <<= 10;
204212
trigger.Emit();
@@ -261,6 +269,76 @@ TYPED_TEST_P(OperationsTest, IterateByRef1)
261269
ASSERT_EQ(x()[i], 123);
262270
}
263271

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+
264342
///////////////////////////////////////////////////////////////////////////////////////////////////
265343
REGISTER_TYPED_TEST_CASE_P
266344
(
@@ -273,7 +351,8 @@ REGISTER_TYPED_TEST_CASE_P
273351
Pulse1,
274352
Snapshot1,
275353
FoldByRef1,
276-
IterateByRef1
354+
IterateByRef1,
355+
GenerateEvents1
277356
);
278357

279358
} // ~namespace

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL