[core] Make ExponentialStops behavior consistent; add tests

This commit is contained in:
John Firebaugh
2017-05-19 11:12:05 -07:00
parent bdff99c853
commit 1f921299b0
5 changed files with 44 additions and 4 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -20,7 +20,6 @@ public:
optional<T> evaluate(float z) const {
if (stops.empty()) {
assert(false);
return {};
}

View File

@@ -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>()))));
}

View File

@@ -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>()))));
}