From 1f921299b0fc43c04cf0d16138d642a5d4e70930 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 19 May 2017 11:12:05 -0700 Subject: [core] Make ExponentialStops behavior consistent; add tests --- cmake/test-files.cmake | 2 ++ include/mbgl/style/function/exponential_stops.hpp | 5 ++--- include/mbgl/style/function/interval_stops.hpp | 1 - test/style/function/exponential_stops.test.cpp | 20 ++++++++++++++++++++ test/style/function/interval_stops.test.cpp | 20 ++++++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/style/function/exponential_stops.test.cpp create mode 100644 test/style/function/interval_stops.test.cpp 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 evaluate(float z) const { if (stops.empty()) { - assert(false); - return T(); + return {}; } auto it = stops.upper_bound(z); @@ -42,7 +41,7 @@ public: optional evaluate(const Value& value) const { optional z = numericValue(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 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 + +#include + +using namespace mbgl; +using namespace mbgl::style; + +TEST(ExponentialStops, Empty) { + ExponentialStops stops; + EXPECT_FALSE(bool(stops.evaluate(0))); +} + +TEST(ExponentialStops, NonNumericInput) { + ExponentialStops stops(std::map {{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())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map())))); +} 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 + +#include + +using namespace mbgl; +using namespace mbgl::style; + +TEST(IntervalStops, Empty) { + IntervalStops stops; + EXPECT_FALSE(bool(stops.evaluate(0))); +} + +TEST(IntervalStops, NonNumericInput) { + IntervalStops stops(std::map {{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())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map())))); +} -- cgit v1.2.1