summaryrefslogtreecommitdiff
path: root/test/math/clamp.test.cpp
blob: 2fdafae1b4e29aa97fffec5c3184e435e0fd0f96 (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
#include <mbgl/test/util.hpp>

#include <mbgl/util/constants.hpp>
#include <mbgl/math/clamp.hpp>

using namespace mbgl;

TEST(Math, ClampFloatingPoint) {
    double lowestValue = std::numeric_limits<double>::lowest();
    double maximumValue = std::numeric_limits<double>::max();
    double quietNAN = std::numeric_limits<double>::quiet_NaN();

    ASSERT_DOUBLE_EQ(0., util::clamp(0., quietNAN, quietNAN));
    ASSERT_DOUBLE_EQ(0., util::clamp(0., lowestValue, maximumValue));
}

TEST(Math, ClampIntegral) {
    int32_t lowestValue = std::numeric_limits<int32_t>::lowest();
    int32_t maximumValue = std::numeric_limits<int32_t>::max();
    int32_t quietNAN = std::numeric_limits<int32_t>::quiet_NaN();

    ASSERT_EQ(0, util::clamp(0, quietNAN, quietNAN));
    ASSERT_EQ(0, util::clamp(0, lowestValue, maximumValue));
}