summaryrefslogtreecommitdiff
path: root/test/math
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-04 17:32:30 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-05 11:16:57 -0700
commitce2a06e6773dfb656c7bf6fdbb7e8bc463710685 (patch)
treed3939aca3d9378a87832f305f68e82bc1fa6fd89 /test/math
parenta81891771441dfc1c839b9d100368b6bbf1fc127 (diff)
downloadqtlocation-mapboxgl-ce2a06e6773dfb656c7bf6fdbb7e8bc463710685.tar.gz
[core] Privatize math.hpp and vec.hpp
Diffstat (limited to 'test/math')
-rw-r--r--test/math/clamp.cpp24
-rw-r--r--test/math/minmax.cpp36
2 files changed, 60 insertions, 0 deletions
diff --git a/test/math/clamp.cpp b/test/math/clamp.cpp
new file mode 100644
index 0000000000..2fdafae1b4
--- /dev/null
+++ b/test/math/clamp.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));
+}
diff --git a/test/math/minmax.cpp b/test/math/minmax.cpp
new file mode 100644
index 0000000000..2e3ebdc340
--- /dev/null
+++ b/test/math/minmax.cpp
@@ -0,0 +1,36 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/util/constants.hpp>
+#include <mbgl/math/minmax.hpp>
+
+using namespace mbgl;
+
+TEST(Math, MinMaxFloatingPoint) {
+ double minimumValue = std::numeric_limits<double>::min();
+ 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(lowestValue, util::min(minimumValue, lowestValue));
+ ASSERT_DOUBLE_EQ(lowestValue, util::min(double(NAN), lowestValue));
+ ASSERT_DOUBLE_EQ(lowestValue, util::min(quietNAN, lowestValue));
+ ASSERT_DOUBLE_EQ(0., util::min(2., 1., 0.));
+
+ ASSERT_DOUBLE_EQ(maximumValue, util::max(double(NAN), maximumValue));
+ ASSERT_DOUBLE_EQ(maximumValue, util::max(quietNAN, maximumValue));
+ ASSERT_DOUBLE_EQ(10., util::max(8., 9., 10.));
+}
+
+TEST(Math, MinMaxIntegral) {
+ int32_t minimumValue = std::numeric_limits<int32_t>::min();
+ 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(lowestValue, util::min(minimumValue, lowestValue));
+ ASSERT_EQ(lowestValue, util::min(quietNAN, lowestValue));
+ ASSERT_EQ(0, util::min(2, 1, 0));
+
+ ASSERT_EQ(maximumValue, util::max(quietNAN, maximumValue));
+ ASSERT_EQ(10, util::max(8, 9, 10));
+}