-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_test1.cc
109 lines (105 loc) · 4.12 KB
/
functional_test1.cc
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "functional.h"
#include "test.h"
#include <cassert>
int
main()
{
const double prec = 0.;
const double dx = 1.;
const auto id = [](auto x) { return x; };
const auto linear = [](auto x) { return x + 42; };
const auto quadratic = [](auto x) { return x * x + x + 42; };
const auto cubic = [](auto x) { return x * x * x + x * x + x + 42; };
for (int i = 0; i < 42; ++i) {
// compose: 0 argumentów
assert(is_equal(compose()(i * dx), i * dx, prec));
// compose: 1 argument
assert(is_equal(compose(id)(i * dx), id(i * dx), prec));
assert(is_equal(compose(linear)(i * dx), linear(i * dx), prec));
assert(is_equal(compose(quadratic)(i * dx), quadratic(i * dx), prec));
assert(is_equal(compose(cubic)(i * dx), cubic(i * dx), prec));
// compose: 2 argumenty
assert(is_equal(compose(id, linear)(i * dx), linear(id(i * dx)), prec));
assert(is_equal(
compose(linear, quadratic)(i * dx), quadratic(linear(i * dx)), prec));
assert(is_equal(
compose(quadratic, cubic)(i * dx), cubic(quadratic(i * dx)), prec));
assert(is_equal(compose(linear, id)(i * dx), id(linear(i * dx)), prec));
assert(is_equal(
compose(quadratic, linear)(i * dx), linear(quadratic(i * dx)), prec));
assert(is_equal(
compose(cubic, quadratic)(i * dx), quadratic(cubic(i * dx)), prec));
assert(
is_equal(compose(linear, linear)(i * dx), linear(linear(i * dx)), prec));
assert(is_equal(compose(quadratic, quadratic)(i * dx),
quadratic(quadratic(i * dx)),
prec));
assert(is_equal(compose(cubic, cubic)(i * dx), cubic(cubic(i * dx)), prec));
// compose: 3 i więcej argumentów
assert(is_equal(compose(id, linear, quadratic)(i * dx),
quadratic(linear(id(i * dx))),
prec));
assert(is_equal(compose(id, linear, quadratic, cubic)(i * dx),
cubic(quadratic(linear(id(i * dx)))),
prec));
assert(is_equal(compose(id, linear, quadratic, cubic, id)(i * dx),
id(cubic(quadratic(linear(id(i * dx))))),
prec));
assert(is_equal(compose(id, linear, quadratic, cubic, id, linear)(i * dx),
linear(id(cubic(quadratic(linear(id(i * dx)))))),
prec));
assert(is_equal(
compose(id, linear, quadratic, cubic, id, linear, quadratic)(i * dx),
quadratic(linear(id(cubic(quadratic(linear(id(i * dx))))))),
prec));
assert(is_equal(
compose(id, linear, quadratic, cubic, id, linear, quadratic, cubic)(i *
dx),
cubic(quadratic(linear(id(cubic(quadratic(linear(id(i * dx)))))))),
prec));
assert(is_equal(compose(id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id,
id)(i * dx), // złożenie 42 funkcji id
i * dx,
prec));
}
}