File: extrapolate_test.cpp

package info (click to toggle)
libfplus 0.2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: cpp: 27,543; javascript: 634; sh: 105; python: 103; makefile: 6
file content (77 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download | duplicates (2)
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
// Copyright 2015, Tobias Hermann and the FunctionalPlus contributors.
// https://github.com/Dobiasd/FunctionalPlus
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include <fplus/fplus.hpp>
#include <vector>


namespace {
    typedef std::vector<int> IntVector;
    IntVector xs = {1,2,2,3,2};
}

TEST_CASE("extrapolate_test, elem_at_idx_or_nothing")
{
    using namespace fplus;
    REQUIRE_EQ(elem_at_idx_or_nothing(-4, xs), nothing<int>());
    REQUIRE_EQ(elem_at_idx_or_nothing(14, xs), nothing<int>());
    REQUIRE_EQ(elem_at_idx_or_nothing(3, xs), maybe<int>(3));
}

TEST_CASE("extrapolate_test, elem_at_idx_or_constant")
{
    using namespace fplus;
    REQUIRE_EQ(elem_at_idx_or_constant(4, -4, xs), 4);
    REQUIRE_EQ(elem_at_idx_or_constant(4, 14, xs), 4);
    REQUIRE_EQ(elem_at_idx_or_constant(4, 3, xs), 3);
}

TEST_CASE("extrapolate_test, elem_at_idx_or_replicate")
{
    using namespace fplus;
    REQUIRE_EQ(elem_at_idx_or_replicate(-2, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_replicate(-1, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_replicate(0, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_replicate(4, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_replicate(5, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_replicate(6, xs), 2);
}

TEST_CASE("extrapolate_test, elem_at_idx_or_wrap")
{
    using namespace fplus;
    REQUIRE_EQ(elem_at_idx_or_wrap(-2, xs), 3);
    REQUIRE_EQ(elem_at_idx_or_wrap(-1, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_wrap(0, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_wrap(4, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_wrap(5, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_wrap(6, xs), 2);
}

TEST_CASE("extrapolate_test, elem_at_idx_or_wrap")
{
    using namespace fplus;
    REQUIRE_EQ(elem_at_idx_or_wrap(-2, xs), 3);
    REQUIRE_EQ(elem_at_idx_or_wrap(-1, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_wrap(0, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_wrap(4, xs), 2);
    REQUIRE_EQ(elem_at_idx_or_wrap(5, xs), 1);
    REQUIRE_EQ(elem_at_idx_or_wrap(6, xs), 2);
}

TEST_CASE("extrapolate_test, extrapolate_replicate")
{
    using namespace fplus;
    REQUIRE_EQ(extrapolate_replicate(2, 2, xs), IntVector({1,1,1,2,2,3,2,2,2}));
}

TEST_CASE("extrapolate_test, extrapolate_wrap")
{
    using namespace fplus;
    REQUIRE_EQ(extrapolate_wrap(2, 2, xs), IntVector({3,2,1,2,2,3,2,1,2}));
}