summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-07-13 18:14:12 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-07-20 11:56:30 -0700
commitc8edbb0500cbf4baf1d5fdb0e63679539e166585 (patch)
tree750f3b72b9e3b1c91ddbc0541cfc64d7d80ffe71 /test/style
parent6d7072162b764c2432c010cd463a5a2c0093d606 (diff)
downloadqtlocation-mapboxgl-c8edbb0500cbf4baf1d5fdb0e63679539e166585.tar.gz
[core] Replace {Source,Camera,Composite}Function with PropertyExpression
Diffstat (limited to 'test/style')
-rw-r--r--test/style/conversion/function.test.cpp15
-rw-r--r--test/style/conversion/light.test.cpp11
-rw-r--r--test/style/conversion/stringify.test.cpp16
-rw-r--r--test/style/function/camera_function.test.cpp32
-rw-r--r--test/style/function/source_function.test.cpp35
-rw-r--r--test/style/properties.test.cpp4
-rw-r--r--test/style/property_expression.test.cpp (renamed from test/style/function/composite_function.test.cpp)63
7 files changed, 72 insertions, 104 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp
index a48be2c075..fa89576afa 100644
--- a/test/style/conversion/function.test.cpp
+++ b/test/style/conversion/function.test.cpp
@@ -2,9 +2,8 @@
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/constant.hpp>
-#include <mbgl/style/conversion/function.hpp>
+#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/data_driven_property_value.hpp>
-#include <mbgl/util/rapidjson.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -14,7 +13,7 @@ TEST(StyleConversion, Function) {
Error error;
auto parseFunction = [&](const std::string& json) {
- return convertJSON<CameraFunction<float>>(json, error);
+ return convertJSON<PropertyValue<float>>(json, error);
};
auto fn1 = parseFunction(R"({"stops":[]})");
@@ -46,7 +45,7 @@ TEST(StyleConversion, Function) {
auto fn8 = parseFunction("[]");
ASSERT_FALSE(fn8);
- ASSERT_EQ("function must be an object", error.message);
+ ASSERT_EQ("value must be a number", error.message);
auto fn9 = parseFunction(R"({"stops":[[0,0]],"base":false})");
ASSERT_FALSE(fn9);
@@ -56,10 +55,8 @@ TEST(StyleConversion, Function) {
TEST(StyleConversion, CompositeFunctionExpression) {
Error error;
- auto parseFunction = [&](const std::string& src) {
- JSDocument doc;
- doc.Parse<0>(src);
- return convert<DataDrivenPropertyValue<float>>(doc, error);
+ auto parseFunction = [&](const std::string& json) {
+ return convertJSON<DataDrivenPropertyValue<float>>(json, error);
};
auto fn1 = parseFunction(R"(["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10])");
@@ -71,7 +68,7 @@ TEST(StyleConversion, CompositeFunctionExpression) {
auto fn3 = parseFunction(R"(["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10] ])");
ASSERT_TRUE(fn3);
- auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0 ])");
+ auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10]], 0])");
ASSERT_TRUE(fn4);
auto fn5 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["number", ["get", "x"]], 0, ["zoom"], 10, 10], 0])");
diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp
index 67e48c942e..f111e40ff3 100644
--- a/test/style/conversion/light.test.cpp
+++ b/test/style/conversion/light.test.cpp
@@ -32,22 +32,23 @@ TEST(StyleConversion, Light) {
ASSERT_TRUE(light->getAnchor().isUndefined());
ASSERT_FALSE(light->getAnchor().isConstant());
- ASSERT_FALSE(light->getAnchor().isCameraFunction());
+ ASSERT_FALSE(light->getAnchor().isExpression());
ASSERT_FALSE(light->getIntensity().isUndefined());
ASSERT_TRUE(light->getIntensity().isConstant());
ASSERT_EQ(light->getIntensity().asConstant(), 0.3f);
- ASSERT_FALSE(light->getAnchor().isCameraFunction());
+ ASSERT_FALSE(light->getIntensity().isExpression());
ASSERT_FALSE(light->getColor().isUndefined());
ASSERT_FALSE(light->getColor().isConstant());
- ASSERT_TRUE(light->getColor().isCameraFunction());
+ ASSERT_TRUE(light->getColor().isExpression());
+ ASSERT_FALSE(light->getColor().asExpression().isZoomConstant());
ASSERT_FALSE(light->getPosition().isUndefined());
ASSERT_TRUE(light->getPosition().isConstant());
std::array<float, 3> expected{{ 3, 90, 90 }};
ASSERT_EQ(light->getPosition().asConstant(), mbgl::style::Position({ expected }));
- ASSERT_FALSE(light->getPosition().isCameraFunction());
+ ASSERT_FALSE(light->getPosition().isExpression());
}
{
@@ -56,7 +57,7 @@ TEST(StyleConversion, Light) {
ASSERT_FALSE(light->getColor().isUndefined());
ASSERT_TRUE(light->getColor().isConstant());
- ASSERT_FALSE(light->getColor().isCameraFunction());
+ ASSERT_FALSE(light->getColor().isExpression());
ASSERT_EQ(light->getColorTransition().duration, mbgl::Duration(mbgl::Milliseconds(1000)));
ASSERT_FALSE((bool) light->getColorTransition().delay);
}
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp
index bc73b0cedb..8bc78098cd 100644
--- a/test/style/conversion/stringify.test.cpp
+++ b/test/style/conversion/stringify.test.cpp
@@ -82,9 +82,9 @@ TEST(Stringify, Filter) {
ASSERT_EQ(stringify(Filter(eq(literal("a"), literal("b")))), "[\"==\",\"a\",\"b\"]");
}
-TEST(Stringify, CameraFunction) {
+TEST(Stringify, PropertyExpression) {
using namespace mbgl::style::expression::dsl;
- ASSERT_EQ(stringify(CameraFunction<float>(
+ ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
linear(),
zoom(),
@@ -92,11 +92,8 @@ TEST(Stringify, CameraFunction) {
1.0, literal(2.0)
))),
"[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]");
-}
-TEST(Stringify, SourceFunction) {
- using namespace mbgl::style::expression::dsl;
- ASSERT_EQ(stringify(SourceFunction<float>(
+ ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
exponential(2.0),
number(get("property")),
@@ -104,11 +101,8 @@ TEST(Stringify, SourceFunction) {
1.0, literal(2.0)
))),
"[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]");
-}
-TEST(Stringify, CompositeFunction) {
- using namespace mbgl::style::expression::dsl;
- ASSERT_EQ(stringify(CompositeFunction<float>(
+ ASSERT_EQ(stringify(PropertyExpression<float>(
interpolate(
linear(),
zoom(),
@@ -125,7 +119,7 @@ TEST(Stringify, CompositeFunction) {
TEST(Stringify, PropertyValue) {
using namespace mbgl::style::expression::dsl;
ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0");
- ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>(
+ ASSERT_EQ(stringify(PropertyValue<float>(PropertyExpression<float>(
interpolate(
exponential(2.0),
zoom(),
diff --git a/test/style/function/camera_function.test.cpp b/test/style/function/camera_function.test.cpp
deleted file mode 100644
index 1f7e81fc2c..0000000000
--- a/test/style/function/camera_function.test.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <iostream>
-#include <mbgl/test/util.hpp>
-
-#include <mbgl/renderer/property_evaluator.hpp>
-#include <mbgl/renderer/property_evaluation_parameters.hpp>
-#include <mbgl/style/expression/dsl.hpp>
-
-using namespace mbgl;
-using namespace mbgl::style;
-using namespace mbgl::style::expression::dsl;
-
-float evaluate(PropertyValue<float> value, float zoom) {
- return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
-}
-
-TEST(CameraFunction, Constant) {
- EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0));
- EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0));
- EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 0));
- EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 4));
- EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 4));
- EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 4));
- EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 22));
- EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 22));
- EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 22));
-}
-
-TEST(CameraFunction, Expression) {
- CameraFunction<float> function(interpolate(linear(), zoom(), 0.0, literal(0.0), 1.0, literal(1.0)));
- EXPECT_EQ(0.0, evaluate(function, 0.0));
- EXPECT_EQ(0.5, evaluate(function, 0.5));
-}
diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp
deleted file mode 100644
index d1e5e1a974..0000000000
--- a/test/style/function/source_function.test.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <mbgl/test/util.hpp>
-#include <mbgl/test/stub_geometry_tile_feature.hpp>
-
-#include <mbgl/style/function/source_function.hpp>
-#include <mbgl/style/expression/dsl.hpp>
-
-using namespace mbgl;
-using namespace mbgl::style;
-
-using namespace std::string_literals;
-
-static StubGeometryTileFeature oneInteger {
- PropertyMap {{ "property", uint64_t(1) }}
-};
-
-static StubGeometryTileFeature oneDouble {
- PropertyMap {{ "property", 1.0 }}
-};
-
-static StubGeometryTileFeature oneString {
- PropertyMap {{ "property", "1"s }}
-};
-
-TEST(SourceFunction, Defaults) {
- using namespace mbgl::style::expression::dsl;
-
- EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0)
- .evaluate(oneInteger, 2.0f));
- EXPECT_EQ(1.0f, SourceFunction<float>(number(get("property")), 0.0)
- .evaluate(oneDouble, 2.0f));
- EXPECT_EQ(0.0f, SourceFunction<float>(number(get("property")), 0.0)
- .evaluate(oneString, 2.0f));
- EXPECT_EQ(2.0f, SourceFunction<float>(number(get("property")))
- .evaluate(oneString, 2.0f));
-}
diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp
index 4d63f7e671..ef064ccba2 100644
--- a/test/style/properties.test.cpp
+++ b/test/style/properties.test.cpp
@@ -123,10 +123,10 @@ TEST(TransitioningDataDrivenPropertyValue, Evaluate) {
};
using namespace mbgl::style::expression::dsl;
- SourceFunction<float> sourceFunction(number(get("property_name")));
+ PropertyExpression<float> expression(number(get("property_name")));
Transitioning<DataDrivenPropertyValue<float>> t1 {
- DataDrivenPropertyValue<float>(sourceFunction),
+ DataDrivenPropertyValue<float>(expression),
t0,
transition,
TimePoint::min()
diff --git a/test/style/function/composite_function.test.cpp b/test/style/property_expression.test.cpp
index 917689ce23..e4ee5f115f 100644
--- a/test/style/function/composite_function.test.cpp
+++ b/test/style/property_expression.test.cpp
@@ -1,7 +1,9 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_geometry_tile_feature.hpp>
-#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/style/property_expression.hpp>
+#include <mbgl/renderer/property_evaluator.hpp>
+#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
@@ -14,8 +16,49 @@ static StubGeometryTileFeature oneInteger {
PropertyMap {{ "property", uint64_t(1) }}
};
-TEST(CompositeFunction, ZoomInterpolation) {
- EXPECT_EQ(40.0f, CompositeFunction<float>(
+static StubGeometryTileFeature oneDouble {
+ PropertyMap {{ "property", 1.0 }}
+};
+
+static StubGeometryTileFeature oneString {
+ PropertyMap {{ "property", "1"s }}
+};
+
+float evaluate(PropertyValue<float> value, float zoom) {
+ return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
+}
+
+TEST(PropertyExpression, Constant) {
+ EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0));
+ EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0));
+ EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 0));
+ EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 4));
+ EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 4));
+ EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 4));
+ EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 22));
+ EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 22));
+ EXPECT_EQ(22.0f, evaluate(PropertyValue<float>(22.0), 22));
+}
+
+TEST(PropertyExpression, Expression) {
+ PropertyExpression<float> expression(interpolate(linear(), zoom(), 0.0, literal(0.0), 1.0, literal(1.0)));
+ EXPECT_EQ(0.0, evaluate(expression, 0.0));
+ EXPECT_EQ(0.5, evaluate(expression, 0.5));
+}
+
+TEST(PropertyExpression, Defaults) {
+ EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0)
+ .evaluate(oneInteger, 2.0f));
+ EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0)
+ .evaluate(oneDouble, 2.0f));
+ EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0)
+ .evaluate(oneString, 2.0f));
+ EXPECT_EQ(2.0f, PropertyExpression<float>(number(get("property")))
+ .evaluate(oneString, 2.0f));
+}
+
+TEST(PropertyExpression, ZoomInterpolation) {
+ EXPECT_EQ(40.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(24.0)),
1.5, interpolate(linear(), number(get("property")), 1.0, literal(36.0)),
@@ -23,28 +66,28 @@ TEST(CompositeFunction, ZoomInterpolation) {
), 0.0f)
.evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops";
- EXPECT_EQ(33.0, CompositeFunction<float>(
+ EXPECT_EQ(33.0, PropertyExpression<float>(
interpolate(linear(), zoom(),
5.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(0.0f, oneInteger, -1.0f)) << "Use first stop output for input values from -inf to first stop";
- EXPECT_EQ(66.0, CompositeFunction<float>(
+ EXPECT_EQ(66.0, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(20.0f, oneInteger, -1.0f)) << "Use last stop output for input values from last stop to +inf";
- EXPECT_EQ(66.0f, CompositeFunction<float>(
+ EXPECT_EQ(66.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
), 0.0f)
.evaluate(10.0f, oneInteger, -1.0f)) << "Should interpolate TO the last stop.";
- EXPECT_EQ(33.0f, CompositeFunction<float>(
+ EXPECT_EQ(33.0f, PropertyExpression<float>(
interpolate(linear(), zoom(),
0.0, interpolate(linear(), number(get("property")), 1.0, literal(33.0)),
10.0, interpolate(linear(), number(get("property")), 1.0, literal(66.0))
@@ -52,8 +95,8 @@ TEST(CompositeFunction, ZoomInterpolation) {
.evaluate(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop";
}
-TEST(CompositeFunction, Issue8460) {
- CompositeFunction<float> fn1(
+TEST(PropertyExpression, Issue8460) {
+ PropertyExpression<float> fn1(
interpolate(linear(), zoom(),
15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2, interpolate(linear(), number(get("property")), 1.0, literal(600.0))
@@ -64,7 +107,7 @@ TEST(CompositeFunction, Issue8460) {
EXPECT_NEAR(600.0f, fn1.evaluate(15.2f, oneInteger, -1.0f), 0.00);
EXPECT_NEAR(600.0f, fn1.evaluate(16.0f, oneInteger, -1.0f), 0.00);
- CompositeFunction<float> fn2(
+ PropertyExpression<float> fn2(
interpolate(linear(), zoom(),
15.0, interpolate(linear(), number(get("property")), 1.0, literal(0.0)),
15.2, interpolate(linear(), number(get("property")), 1.0, literal(300.0)),