-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
40 lines (37 loc) · 796 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <assert.h>
#include <iostream>
#include "math.h"
#include "signal.h"
#include <vector>
void testSignalVoid()
{
Signal<void ()> sig;
auto id = sig.connect([]() { assert(true); });
sig();
sig.emit();
sig.disconnect(id);
sig.clear();
}
void testSignalValue()
{
Signal<int (int)> sig;
auto id1 = sig.connect([](int x) { return x + x; });
auto id2 = sig.connect([](int x) { return x * x; });
auto id3 = sig.connect([](int x) { return pow(x, x); });
auto op = [](std::vector<int> lhs, int rhs)->std::vector<int>
{
lhs.push_back(rhs);
return lhs;
};
auto vals = sig.emit<std::vector<int>>(op, 3);
assert(vals[0] == 6);
assert(vals[1] == 9);
assert(vals[2] == 27);
sig.clear();
}
int main()
{
testSignalVoid();
testSignalValue();
return 0;
}