From 542a4b4501794653b55fd1ffc60cb01348d8fc88 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 27 Jun 2018 16:57:23 -0700 Subject: [core] Replace use of *Stops with expressions DSL --- test/api/query.test.cpp | 20 ++++--- test/programs/symbol_program.test.cpp | 52 ++++++++++------- test/renderer/group_by_layout.test.cpp | 6 +- test/style/conversion/stringify.test.cpp | 73 +++++++++++++----------- test/style/function/camera_function.test.cpp | 59 ++----------------- test/style/function/composite_function.test.cpp | 69 ++++++++++++---------- test/style/function/source_function.test.cpp | 76 +++---------------------- test/style/properties.test.cpp | 11 ++-- 8 files changed, 143 insertions(+), 223 deletions(-) (limited to 'test') diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index ffab52692b..5960de3b31 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -67,20 +68,20 @@ TEST(Query, QueryRenderedFeaturesFilterLayer) { } TEST(Query, QueryRenderedFeaturesFilter) { - QueryTest test; - ParsingContext context; + using namespace mbgl::style::expression::dsl; + QueryTest test; auto zz = test.map.pixelForLatLng({ 0, 0 }); - const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context)); + const Filter eqFilter(eq(get("key1"), literal("value1"))); auto features1 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{}, { eqFilter }}); EXPECT_EQ(features1.size(), 1u); - const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context)); + const Filter idNotEqFilter(ne(id(), literal("feature1"))); auto features2 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{{ "layer4" }}, { idNotEqFilter }}); EXPECT_EQ(features2.size(), 0u); - const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context)); + const Filter gtFilter(gt(number(get("key2")), literal(1.0))); auto features3 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{ }, { gtFilter }}); EXPECT_EQ(features3.size(), 1u); } @@ -109,18 +110,19 @@ TEST(Query, QuerySourceFeaturesOptionValidation) { } TEST(Query, QuerySourceFeaturesFilter) { + using namespace mbgl::style::expression::dsl; + QueryTest test; - ParsingContext context; - const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context)); + const Filter eqFilter(eq(get("key1"), literal("value1"))); auto features1 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { eqFilter }}); EXPECT_EQ(features1.size(), 1u); - const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context)); + const Filter idNotEqFilter(ne(id(), literal("feature1"))); auto features2 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { idNotEqFilter }}); EXPECT_EQ(features2.size(), 0u); - const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context)); + const Filter gtFilter(gt(number(get("key2")), literal(1.0))); auto features3 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { gtFilter }}); EXPECT_EQ(features3.size(), 1u); } diff --git a/test/programs/symbol_program.test.cpp b/test/programs/symbol_program.test.cpp index 62a2e58d7b..ed709a4ba7 100644 --- a/test/programs/symbol_program.test.cpp +++ b/test/programs/symbol_program.test.cpp @@ -1,8 +1,10 @@ #include #include +#include using namespace mbgl; +using namespace mbgl::style::expression::dsl; TEST(SymbolProgram, SymbolSizeBinder) { auto binder = SymbolSizeBinder::create(5.0f, 12.0f, 0.0f); @@ -11,45 +13,55 @@ TEST(SymbolProgram, SymbolSizeBinder) { EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 12.0f); - binder = SymbolSizeBinder::create(1.0f, style::CameraFunction(style::ExponentialStops({ - {0.0f, 8.0f}, - {10.0f, 18.0f} - }, 1.0f)), 0.0f); + binder = SymbolSizeBinder::create(1.0f, style::CameraFunction( + interpolate( + linear(), + zoom(), + 0., literal(8.), + 10., literal(18.))), 0.0f); uniformValues = binder->uniformValues(1.5f); EXPECT_EQ(uniformValues.get().t, false); EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 9.5f); - binder = SymbolSizeBinder::create(0.0f, style::CameraFunction(style::ExponentialStops({ - {1.0f, 8.0f}, - {11.0f, 18.0f} - }, 1.0f)), 0.0f); + binder = SymbolSizeBinder::create(0.0f, style::CameraFunction( + interpolate( + linear(), + zoom(), + 1., literal(8.), + 11., literal(18.))), 0.0f); uniformValues = binder->uniformValues(0.5f); EXPECT_EQ(uniformValues.get().t, false); EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 8.0f); - binder = SymbolSizeBinder::create(12.0f, style::CameraFunction(style::ExponentialStops({ - {1.0f, 8.0f}, - {11.0f, 18.0f} - }, 1.0f)), 0.0f); + binder = SymbolSizeBinder::create(12.0f, style::CameraFunction( + interpolate( + linear(), + zoom(), + 1., literal(8.), + 11., literal(18.))), 0.0f); uniformValues = binder->uniformValues(12.5f); EXPECT_EQ(uniformValues.get().t, false); EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, 18.0f); - binder = SymbolSizeBinder::create(0.0f, style::SourceFunction("x", style::ExponentialStops({ - {1.0f, 8.0f}, - {11.0f, 18.0f} - }, 1.0f)), 0.0f); + binder = SymbolSizeBinder::create(0.0f, style::SourceFunction( + interpolate( + linear(), + number(get("x")), + 1., literal(8.), + 11., literal(18.))), 0.0f); uniformValues = binder->uniformValues(12.5f); EXPECT_EQ(uniformValues.get().t, true); EXPECT_EQ(uniformValues.get().t, false); - binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction("x", style::CompositeExponentialStops({ - {1.0f, {{0.0f, 8.0f}, {100.0f, 18.0f}}}, - {11.0f, {{0.0f, 12.0f}, {100.0f, 24.9f}}} - }, 1.0f)), 0.0f); + binder = SymbolSizeBinder::create(5.0f, style::CompositeFunction( + interpolate( + linear(), + zoom(), + 1., interpolate(linear(), number(get("x")), 0., literal(8.), 100., literal(18.)), + 11., interpolate(linear(), number(get("x")), 0., literal(12.), 100., literal(24.9)))), 0.0f); uniformValues = binder->uniformValues(5.5f); EXPECT_EQ(uniformValues.get().t, false); EXPECT_EQ(uniformValues.get().t, false); diff --git a/test/renderer/group_by_layout.test.cpp b/test/renderer/group_by_layout.test.cpp index 6cf17e2279..8d0b432481 100644 --- a/test/renderer/group_by_layout.test.cpp +++ b/test/renderer/group_by_layout.test.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include using namespace mbgl; using namespace mbgl::style; @@ -38,11 +38,11 @@ TEST(GroupByLayout, UnrelatedType) { } TEST(GroupByLayout, UnrelatedFilter) { + using namespace mbgl::style::expression::dsl; std::vector> layers; layers.push_back(std::make_unique("a", "source")); layers.push_back(std::make_unique("b", "source")); - ParsingContext context; - layers[0]->as()->setFilter(Filter(createCompoundExpression("filter-has-id", context))); + layers[0]->as()->setFilter(Filter(get("property"))); auto result = groupByLayout(toRenderLayers(layers)); ASSERT_EQ(2u, result.size()); } diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index c3faf1f838..567c022036 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -76,56 +77,62 @@ TEST(Stringify, Value) { } TEST(Stringify, Filter) { - using namespace mbgl::style::expression; - + using namespace mbgl::style::expression::dsl; ASSERT_EQ(stringify(Filter()), "null"); - - ParsingContext context; - ASSERT_EQ(stringify(Filter(createCompoundExpression("filter-==", createLiteral("a"), createLiteral(1.0), context))), "[\"filter-==\",\"a\",1.0]"); + ASSERT_EQ(stringify(Filter(eq(literal("a"), literal(1.0)))), "[\"==\",\"a\",1.0]"); } TEST(Stringify, CameraFunction) { - ASSERT_EQ(stringify(CameraFunction(ExponentialStops { {{0, 1}}, 1 })), - "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0]"); - ASSERT_EQ(stringify(CameraFunction(ExponentialStops { {{0, 1}}, 2 })), - "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); - ASSERT_EQ(stringify(CameraFunction(IntervalStops { {{0, 1}} })), - "[\"step\",[\"zoom\"],0.0,1.0]"); + using namespace mbgl::style::expression::dsl; + ASSERT_EQ(stringify(CameraFunction( + interpolate( + linear(), + zoom(), + 0.0, literal(1.0), + 1.0, literal(2.0) + ))), + "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0,1.0,2.0]"); } TEST(Stringify, SourceFunction) { - ASSERT_EQ(stringify(SourceFunction("property", ExponentialStops { {{0, 1}}, 2 })), - "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]"); - ASSERT_EQ(stringify(SourceFunction("property", IntervalStops { {{0, 1}} })), - "[\"step\",[\"number\",[\"get\",\"property\"]],0.0,1.0]"); - ASSERT_EQ(stringify(SourceFunction("property", CategoricalStops { {{CategoricalValue(true), 1}} })), - "[\"case\",[\"boolean\",[\"get\",\"property\"]],1.0,[\"error\"]]"); - ASSERT_EQ(stringify(SourceFunction("property", IdentityStops {})), - "[\"number\",[\"get\",\"property\"]]"); - ASSERT_EQ(stringify(SourceFunction("property", IdentityStops {}, 0.0f)), - "[\"number\",[\"get\",\"property\"]]"); + using namespace mbgl::style::expression::dsl; + ASSERT_EQ(stringify(SourceFunction( + interpolate( + exponential(2.0), + number(get("property")), + 0.0, literal(1.0), + 1.0, literal(2.0) + ))), + "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]"); } TEST(Stringify, CompositeFunction) { - ASSERT_EQ(stringify(CompositeFunction("property", - CompositeExponentialStops { - { - { 0, {{0, 1}} }, - { 1, {{0, 1}} } - }, - 2 - }, 0.0f)), + using namespace mbgl::style::expression::dsl; + ASSERT_EQ(stringify(CompositeFunction( + interpolate( + linear(), + zoom(), + 0.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)), + 1.0, interpolate(exponential(2.0), number(get("property")), 0.0, literal(1.0), 1.0, literal(2.0)) + ))), "[\"interpolate\"," "[\"linear\"]," "[\"zoom\"]," - "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]," - "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]]"); + "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]," + "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0,1.0,2.0]]"); } TEST(Stringify, PropertyValue) { + using namespace mbgl::style::expression::dsl; ASSERT_EQ(stringify(PropertyValue(1)), "1.0"); - ASSERT_EQ(stringify(PropertyValue(CameraFunction(ExponentialStops { {{0, 1}}, 2 }))), - "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); + ASSERT_EQ(stringify(PropertyValue(CameraFunction( + interpolate( + exponential(2.0), + zoom(), + 0.0, literal(1.0), + 1.0, literal(2.0) + )))), + "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0,1.0,2.0]"); } TEST(Stringify, Layout) { diff --git a/test/style/function/camera_function.test.cpp b/test/style/function/camera_function.test.cpp index 59e3f2cef3..1f7e81fc2c 100644 --- a/test/style/function/camera_function.test.cpp +++ b/test/style/function/camera_function.test.cpp @@ -3,19 +3,15 @@ #include #include +#include using namespace mbgl; using namespace mbgl::style; +using namespace mbgl::style::expression::dsl; float evaluate(PropertyValue value, float zoom) { return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), 0)); } -std::string evaluate(PropertyValue value, float zoom) { - return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), "")); -} -bool evaluate(PropertyValue value, float zoom) { - return value.evaluate(PropertyEvaluator(PropertyEvaluationParameters(zoom), false)); -} TEST(CameraFunction, Constant) { EXPECT_EQ(2.0f, evaluate(PropertyValue(2.0), 0)); @@ -29,51 +25,8 @@ TEST(CameraFunction, Constant) { EXPECT_EQ(22.0f, evaluate(PropertyValue(22.0), 22)); } -TEST(CameraFunction, Stops) { - // Explicit constant slope in fringe regions. - CameraFunction slope_1(ExponentialStops { { { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75}); - EXPECT_EQ(1.5, evaluate(slope_1, 0)); - EXPECT_EQ(1.5, evaluate(slope_1, 4)); - EXPECT_EQ(1.5, evaluate(slope_1, 6)); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, 7)); - EXPECT_EQ(3.0, evaluate(slope_1, 8)); - EXPECT_EQ(3.0, evaluate(slope_1, 9)); - EXPECT_EQ(3.0, evaluate(slope_1, 15)); - EXPECT_EQ(3.0, evaluate(slope_1, 22)); - - - // Test constant values in fringe regions. - CameraFunction slope_2(ExponentialStops { { { 6, 1.5 }, { 8, 3 } }, 1.75 }); - EXPECT_EQ(1.5, evaluate(slope_2, 0)); - EXPECT_EQ(1.5, evaluate(slope_2, 4)); - EXPECT_EQ(1.5, evaluate(slope_2, 6)); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, 7)); - EXPECT_EQ(3.0, evaluate(slope_2, 8)); - EXPECT_EQ(3.0, evaluate(slope_2, 9)); - EXPECT_EQ(3.0, evaluate(slope_2, 15)); - EXPECT_EQ(3.0, evaluate(slope_2, 22)); - - - // Explicit constant slope in fringe regions. - CameraFunction slope_4(ExponentialStops { { { 0, 2 }, { 8, 10 } }, 1 }); - EXPECT_EQ(2, evaluate(slope_4, 0)); - EXPECT_EQ(3, evaluate(slope_4, 1)); - EXPECT_EQ(4, evaluate(slope_4, 2)); - EXPECT_EQ(4.75, evaluate(slope_4, 2.75)); - EXPECT_EQ(10, evaluate(slope_4, 8)); - - // discrete values - CameraFunction discrete_0(IntervalStops { {{3, "string0"}, {6, "string1"}, {9, "string2"}} }); - EXPECT_EQ("string0", evaluate(discrete_0, 2)); - EXPECT_EQ("string0", evaluate(discrete_0, 4)); - EXPECT_EQ("string1", evaluate(discrete_0, 7)); - EXPECT_EQ("string2", evaluate(discrete_0, 9)); - EXPECT_EQ("string2", evaluate(discrete_0, 10)); - - CameraFunction discreteBool(IntervalStops { {{1, false}, {3, true}} }); - EXPECT_FALSE(evaluate(discreteBool, 0)); - EXPECT_FALSE(evaluate(discreteBool, 1)); - EXPECT_FALSE(evaluate(discreteBool, 2)); - EXPECT_TRUE(evaluate(discreteBool, 3)); - EXPECT_TRUE(evaluate(discreteBool, 4)); +TEST(CameraFunction, Expression) { + CameraFunction 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/composite_function.test.cpp b/test/style/function/composite_function.test.cpp index 09b79a8b8f..917689ce23 100644 --- a/test/style/function/composite_function.test.cpp +++ b/test/style/function/composite_function.test.cpp @@ -2,9 +2,11 @@ #include #include +#include using namespace mbgl; using namespace mbgl::style; +using namespace mbgl::style::expression::dsl; using namespace std::string_literals; @@ -13,54 +15,61 @@ static StubGeometryTileFeature oneInteger { }; TEST(CompositeFunction, ZoomInterpolation) { - EXPECT_EQ(40.0f, CompositeFunction("property", CompositeExponentialStops({ - {0.0f, {{uint64_t(1), 24.0f}}}, - {1.5f, {{uint64_t(1), 36.0f}}}, - {3.0f, {{uint64_t(1), 48.0f}}} - }), 0.0f) + EXPECT_EQ(40.0f, CompositeFunction( + 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)), + 3.0, interpolate(linear(), number(get("property")), 1.0, literal(48.0)) + ), 0.0f) .evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops"; - EXPECT_EQ(33.0, CompositeFunction("property", CompositeExponentialStops({ - {5.0f, {{uint64_t(1), 33.0f}}}, - {10.0f, {{uint64_t(1), 66.0f}}} - }), 0.0f) + EXPECT_EQ(33.0, CompositeFunction( + 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("property", CompositeExponentialStops({ - {0.0f, {{uint64_t(1), 33.0f}}}, - {10.0f, {{uint64_t(1), 66.0f}}} - }), 0.0f) + EXPECT_EQ(66.0, CompositeFunction( + 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("property", CompositeExponentialStops({ - {0.0f, {{uint64_t(1), 33.0f}}}, - {10.0f, {{uint64_t(1), 66.0f}}} - }), 0.0f) + EXPECT_EQ(66.0f, CompositeFunction( + 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("property", CompositeExponentialStops({ - {0.0f, {{uint64_t(1), 33.0f}}}, - {10.0f, {{uint64_t(1), 66.0f}}} - }), 0.0f) + EXPECT_EQ(33.0f, CompositeFunction( + 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(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop"; } TEST(CompositeFunction, Issue8460) { - CompositeFunction fn1("property", CompositeExponentialStops({ - {15.0f, {{uint64_t(1), 0.0f}}}, - {15.2f, {{uint64_t(1), 600.0f}}}, - }), 0.0f); + CompositeFunction 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)) + ), 0.0f); EXPECT_NEAR( 0.0f, fn1.evaluate(15.0f, oneInteger, -1.0f), 0.00); EXPECT_NEAR(300.0f, fn1.evaluate(15.1f, oneInteger, -1.0f), 0.01); 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 fn2("property", CompositeExponentialStops({ - {15.0f, {{uint64_t(1), 0.0f}}}, - {15.2f, {{uint64_t(1), 300.0f}}}, - {18.0f, {{uint64_t(1), 600.0f}}}, - }), 0.0f); + CompositeFunction 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)), + 18.0, interpolate(linear(), number(get("property")), 1.0, literal(600.0)) + ), 0.0f); EXPECT_NEAR( 0.0f, fn2.evaluate(15.0f, oneInteger, -1.0f), 0.00); EXPECT_NEAR(150.0f, fn2.evaluate(15.1f, oneInteger, -1.0f), 0.01); diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp index 46ad961002..d1e5e1a974 100644 --- a/test/style/function/source_function.test.cpp +++ b/test/style/function/source_function.test.cpp @@ -2,6 +2,7 @@ #include #include +#include using namespace mbgl; using namespace mbgl::style; @@ -20,78 +21,15 @@ static StubGeometryTileFeature oneString { PropertyMap {{ "property", "1"s }} }; -static StubGeometryTileFeature red { - PropertyMap {{ "property", "red"s }} -}; - -static StubGeometryTileFeature oneTwoInteger { - PropertyMap {{ "property", std::vector({uint64_t(1), uint64_t(2)}) }} -}; - -static StubGeometryTileFeature oneTwoDouble { - PropertyMap {{ "property", std::vector({1.0, 2.0}) }} -}; - -static StubGeometryTileFeature oneTwoString { - PropertyMap {{ "property", std::vector({"1"s, "2"s}) }} -}; - -static StubGeometryTileFeature trueFeature { - PropertyMap {{ "property", true }} -}; +TEST(SourceFunction, Defaults) { + using namespace mbgl::style::expression::dsl; -static StubGeometryTileFeature falseFeature { - PropertyMap {{ "property", false }} -}; - -TEST(SourceFunction, Identity) { - EXPECT_EQ(1.0f, SourceFunction("property", IdentityStops(), 0.0f) + EXPECT_EQ(1.0f, SourceFunction(number(get("property")), 0.0) .evaluate(oneInteger, 2.0f)); - EXPECT_EQ(1.0f, SourceFunction("property", IdentityStops(), 0.0f) + EXPECT_EQ(1.0f, SourceFunction(number(get("property")), 0.0) .evaluate(oneDouble, 2.0f)); - EXPECT_EQ(0.0f, SourceFunction("property", IdentityStops(), 0.0f) + EXPECT_EQ(0.0f, SourceFunction(number(get("property")), 0.0) .evaluate(oneString, 2.0f)); - EXPECT_EQ(2.0f, SourceFunction("property", IdentityStops()) + EXPECT_EQ(2.0f, SourceFunction(number(get("property"))) .evaluate(oneString, 2.0f)); - - EXPECT_EQ(Color::red(), SourceFunction("property", IdentityStops(), Color::black()) - .evaluate(red, Color::black())); - EXPECT_EQ(Color::black(), SourceFunction("property", IdentityStops(), Color::black()) - .evaluate(oneInteger, Color::black())); - - std::array zeroArray {{ 0, 0 }}; - EXPECT_EQ((std::array {{ 1, 2 }}), (SourceFunction>("property", IdentityStops>(), zeroArray) - .evaluate(oneTwoInteger, zeroArray))); - EXPECT_EQ((std::array {{ 1, 2 }}), (SourceFunction>("property", IdentityStops>(), zeroArray) - .evaluate(oneTwoDouble, zeroArray))); - EXPECT_EQ((std::array {{ 0, 0 }}), (SourceFunction>("property", IdentityStops>(), zeroArray) - .evaluate(oneTwoString, zeroArray))); -} - -TEST(SourceFunction, Categorical) { - EXPECT_EQ(1.0f, SourceFunction("property", CategoricalStops({{ int64_t(1), 1.0f }})) - .evaluate(oneInteger, 0.0f)); - EXPECT_EQ(1.0f, SourceFunction("property", CategoricalStops({{ int64_t(1), 1.0f }})) - .evaluate(oneDouble, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction("property", CategoricalStops({{ int64_t(1), 1.0f }})) - .evaluate(oneString, 0.0f)); - - CategoricalStops::Stops stops; - stops["1"s] = 1.0f; - - EXPECT_EQ(0.0f, SourceFunction("property", CategoricalStops(stops)) - .evaluate(oneInteger, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction("property", CategoricalStops(stops)) - .evaluate(oneDouble, 0.0f)); - EXPECT_EQ(1.0f, SourceFunction("property", CategoricalStops(stops)) - .evaluate(oneString, 0.0f)); - - EXPECT_EQ(1.0f, SourceFunction("property", CategoricalStops({{ true, 1.0f }})) - .evaluate(trueFeature, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction("property", CategoricalStops({{ true, 1.0f }})) - .evaluate(falseFeature, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction("property", CategoricalStops({{ false, 1.0f }})) - .evaluate(trueFeature, 0.0f)); - EXPECT_EQ(1.0f, SourceFunction("property", CategoricalStops({{ false, 1.0f }})) - .evaluate(falseFeature, 0.0f)); } diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp index 279fadb8c2..4d63f7e671 100644 --- a/test/style/properties.test.cpp +++ b/test/style/properties.test.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -120,12 +121,10 @@ TEST(TransitioningDataDrivenPropertyValue, Evaluate) { TransitionOptions(), TimePoint::min() }; - - SourceFunction sourceFunction = { - "property_name", - IdentityStops() - }; - + + using namespace mbgl::style::expression::dsl; + SourceFunction sourceFunction(number(get("property_name"))); + Transitioning> t1 { DataDrivenPropertyValue(sourceFunction), t0, -- cgit v1.2.1