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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include "../catch.hpp"
#include "rkcommon/math/range.h"
using namespace rkcommon::math;
#define RUN_FOR_ALL_TYPES(name) \
name<range1f>(); \
name<range2f>(); \
name<range3f>(); \
name<range4f>(); \
name<range1i>(); \
name<range2i>(); \
name<range3i>(); \
name<range4i>();
template <typename T>
inline void test_size()
{
using B = typename T::bound_t;
REQUIRE(T(1, 2).size() == B(1));
}
TEST_CASE("range size function", "[range]")
{
RUN_FOR_ALL_TYPES(test_size);
}
template <typename T>
inline void test_center()
{
using B = typename T::bound_t;
REQUIRE(T(0, 2).center() == B(1));
}
TEST_CASE("range center function", "[range]")
{
RUN_FOR_ALL_TYPES(test_center);
}
template <typename T>
inline void test_extend()
{
using B = typename T::bound_t;
T r(0, 2);
SECTION("by value")
{
r.extend(B(3));
REQUIRE(r == T(0, 3));
}
SECTION("by range")
{
r.extend(T(-1, 3));
REQUIRE(r == T(-1, 3));
}
}
TEST_CASE("range extend function", "[range]")
{
RUN_FOR_ALL_TYPES(test_extend);
}
template <typename T>
inline void test_clamp()
{
using B = typename T::bound_t;
REQUIRE(T(0, 2).clamp(1) == B(1));
REQUIRE(T(0, 2).clamp(-1) == B(0));
REQUIRE(T(0, 2).clamp(3) == B(2));
}
TEST_CASE("range clamp function", "[range]")
{
RUN_FOR_ALL_TYPES(test_clamp);
}
template <typename T>
inline void test_empty()
{
REQUIRE(T(1, 0).empty() == true);
REQUIRE(T(1, 1).empty() == false);
REQUIRE(T(0, 1).empty() == false);
}
TEST_CASE("range empty function", "[range]")
{
RUN_FOR_ALL_TYPES(test_empty);
}
template <typename T>
inline void test_contains()
{
REQUIRE(T(0, 2).contains(-1) == false);
REQUIRE(T(0, 2).contains(0) == true);
REQUIRE(T(0, 2).contains(1) == true);
REQUIRE(T(0, 2).contains(2) == true);
REQUIRE(T(0, 2).contains(3) == false);
}
TEST_CASE("range contains function", "[range]")
{
RUN_FOR_ALL_TYPES(test_contains);
}
template <typename T>
inline void test_scale()
{
using B = typename T::bound_t;
REQUIRE(T(1, 2) * B(2) == T(2, 4));
REQUIRE(B(2) * T(1, 2) == T(2, 4));
}
TEST_CASE("range scale (*) operator", "[range]")
{
RUN_FOR_ALL_TYPES(test_scale);
}
template <typename T>
inline void test_translate()
{
using B = typename T::bound_t;
REQUIRE(T(1, 2) + B(1) == T(2, 3));
REQUIRE(B(1) + T(1, 2) == T(2, 3));
}
TEST_CASE("range translate (+) operator", "[range]")
{
RUN_FOR_ALL_TYPES(test_translate);
}
template <typename T>
inline void test_comparison()
{
REQUIRE(T(0, 1) == T(0, 1));
REQUIRE(T(0, 1) != T(1, 1));
}
TEST_CASE("range comparison operators", "[range]")
{
RUN_FOR_ALL_TYPES(test_comparison);
}
|