-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
71 lines (63 loc) · 1.54 KB
/
main.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
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
#include "TestUtils.hpp"
#include "Compose.hpp"
#include <string>
#include <cmath>
namespace {
int addTwo(int a)
{
return a + 2;
}
int powTwo(int a)
{
return std::pow(a, 2);
}
int powN(int a, int n)
{
return std::pow(a, n);
}
} // namespace anonymous
int main()
{
TestUtils::check(12, []{
const auto f = compose(addTwo);
return f(10);
});
TestUtils::check(14, []{
const auto f = compose(addTwo, addTwo);
return f(10);
});
TestUtils::check(16, []{
const auto f = compose(addTwo, addTwo, addTwo);
return f(10);
});
TestUtils::check(18, []{
const auto f = compose(addTwo, addTwo, addTwo, addTwo);
return f(10);
});
TestUtils::check(144, []{
const auto f = compose(addTwo, powTwo);
return f(10);
});
TestUtils::check(27, []{
const auto f = compose(powN, addTwo);
return f(5, 2);
});
TestUtils::check("012", []{
const auto f = compose(
[](const auto& s){return std::string(s);},
[](const auto& s){return s.size();},
[](const auto n){
auto result = std::string();
for (std::size_t i = 0; i < n; ++i)
result += std::to_string(i);
return result;
}
);
return f("abc");
});
TestUtils::check(std::size_t(3), []{
const auto i = std::string("abc");
const auto f = compose([](const auto& s){return s.size();});
return f(i);
});
}