summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-19 11:12:05 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-19 11:48:45 -0700
commit1f921299b0fc43c04cf0d16138d642a5d4e70930 (patch)
tree505a7ba89e4d8fc54d2bacd7291e86e6134234f1
parentbdff99c853431b89b56ac9a71dc73a65bc5515df (diff)
downloadqtlocation-mapboxgl-1f921299b0fc43c04cf0d16138d642a5d4e70930.tar.gz
[core] Make ExponentialStops behavior consistent; add tests
-rw-r--r--cmake/test-files.cmake2
-rw-r--r--include/mbgl/style/function/exponential_stops.hpp5
-rw-r--r--include/mbgl/style/function/interval_stops.hpp1
-rw-r--r--test/style/function/exponential_stops.test.cpp20
-rw-r--r--test/style/function/interval_stops.test.cpp20
5 files changed, 44 insertions, 4 deletions
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake
index e4ffba4754..83b935d63f 100644
--- a/cmake/test-files.cmake
+++ b/cmake/test-files.cmake
@@ -94,6 +94,8 @@ set(MBGL_TEST_FILES
# style/function
test/style/function/camera_function.test.cpp
test/style/function/composite_function.test.cpp
+ test/style/function/exponential_stops.test.cpp
+ test/style/function/interval_stops.test.cpp
test/style/function/source_function.test.cpp
# style
diff --git a/include/mbgl/style/function/exponential_stops.hpp b/include/mbgl/style/function/exponential_stops.hpp
index 1c57ec6f5d..b3866c4059 100644
--- a/include/mbgl/style/function/exponential_stops.hpp
+++ b/include/mbgl/style/function/exponential_stops.hpp
@@ -24,8 +24,7 @@ public:
optional<T> evaluate(float z) const {
if (stops.empty()) {
- assert(false);
- return T();
+ return {};
}
auto it = stops.upper_bound(z);
@@ -42,7 +41,7 @@ public:
optional<T> evaluate(const Value& value) const {
optional<float> z = numericValue<float>(value);
if (!z) {
- return T();
+ return {};
}
return evaluate(*z);
}
diff --git a/include/mbgl/style/function/interval_stops.hpp b/include/mbgl/style/function/interval_stops.hpp
index a482a6081c..45e2dc6f2e 100644
--- a/include/mbgl/style/function/interval_stops.hpp
+++ b/include/mbgl/style/function/interval_stops.hpp
@@ -20,7 +20,6 @@ public:
optional<T> evaluate(float z) const {
if (stops.empty()) {
- assert(false);
return {};
}
diff --git a/test/style/function/exponential_stops.test.cpp b/test/style/function/exponential_stops.test.cpp
new file mode 100644
index 0000000000..81438ec952
--- /dev/null
+++ b/test/style/function/exponential_stops.test.cpp
@@ -0,0 +1,20 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/function/exponential_stops.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+TEST(ExponentialStops, Empty) {
+ ExponentialStops<float> stops;
+ EXPECT_FALSE(bool(stops.evaluate(0)));
+}
+
+TEST(ExponentialStops, NonNumericInput) {
+ ExponentialStops<float> stops(std::map<float, float> {{0.0f, 0.0f}});
+ EXPECT_FALSE(bool(stops.evaluate(Value(NullValue()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(false))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::string()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::vector<Value>()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map<std::string, Value>()))));
+}
diff --git a/test/style/function/interval_stops.test.cpp b/test/style/function/interval_stops.test.cpp
new file mode 100644
index 0000000000..8a5e74b8b6
--- /dev/null
+++ b/test/style/function/interval_stops.test.cpp
@@ -0,0 +1,20 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/function/interval_stops.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+TEST(IntervalStops, Empty) {
+ IntervalStops<float> stops;
+ EXPECT_FALSE(bool(stops.evaluate(0)));
+}
+
+TEST(IntervalStops, NonNumericInput) {
+ IntervalStops<float> stops(std::map<float, float> {{0.0f, 0.0f}});
+ EXPECT_FALSE(bool(stops.evaluate(Value(NullValue()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(false))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::string()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::vector<Value>()))));
+ EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map<std::string, Value>()))));
+}