summaryrefslogtreecommitdiff
path: root/test/math/clamp.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/math/clamp.test.cpp')
-rw-r--r--test/math/clamp.test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/math/clamp.test.cpp b/test/math/clamp.test.cpp
new file mode 100644
index 0000000000..2fdafae1b4
--- /dev/null
+++ b/test/math/clamp.test.cpp
@@ -0,0 +1,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));
+}