aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
blob: dfcd357456bc48b642a93bc94e2770f0997f6e9d (plain)
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
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sibs/Functional.hpp>

void assertEquals(int expected, int actual)
{
    if(actual != expected)
    {
        fprintf(stderr, "Assert failed: Expected %d, got %d\n", expected, actual);
        exit(1);
    }
}

int main(int argc, char **argv)
{
    std::vector<int> vec1 = { 1, 2, 3, 4, 5 };
    std::vector<int> vec2 = { 6, 7, 8, 9, 10 };
    int sum = 0;

    sibs::Function<int> func1(vec1.data(), vec1.data() + vec1.size());
    for(auto value : func1)
    {
        printf("func1 value: %d\n", value);
        sum += value;
    }
    assertEquals(15, sum);
    sum = 0;

    sibs::Function<int> func2(vec2);
    for(auto value : func2)
    {
        printf("func2 value: %d\n", value);
        sum += value;
    }
    assertEquals(40, sum);
    sum = 0;

    for(auto value : func1.merge(func2))
    {
        printf("func1 and func2 value: %d\n", value);
        sum += value;
    }
    assertEquals(55, sum);

    return 0;
}