diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-01-31 15:44:18 +0200 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-02 09:44:42 -0800 |
commit | 8a5bff8ee630673c6ebc496322eab94a41ae9353 (patch) | |
tree | 8bb6428cd9c3d591c237d77f94d4b0e56efb0ee0 /test/style | |
parent | 141e995806576364d185626176c1b993fc519291 (diff) | |
download | qtlocation-mapboxgl-8a5bff8ee630673c6ebc496322eab94a41ae9353.tar.gz |
[core] default value support in categorical function conversion
Diffstat (limited to 'test/style')
-rw-r--r-- | test/style/conversion/stringify.test.cpp | 6 | ||||
-rw-r--r-- | test/style/function/source_function.test.cpp | 94 |
2 files changed, 98 insertions, 2 deletions
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 6814563ceb..dd04789d4b 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -95,6 +95,8 @@ TEST(Stringify, SourceFunction) { "{\"property\":\"property\",\"type\":\"categorical\",\"stops\":[[true,1.0]]}"); ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {})), "{\"property\":\"property\",\"type\":\"identity\"}"); + ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {}, 0.0f)), + "{\"property\":\"property\",\"type\":\"identity\",\"default\":0.0}"); } TEST(Stringify, CompositeFunction) { @@ -102,11 +104,11 @@ TEST(Stringify, CompositeFunction) { std::map<float, ExponentialStops<float>> { { 0, ExponentialStops<float> { {{0, 1}}, 2 } }, { 1, ExponentialStops<float> { {{0, 1}}, 2 } } - })), + }, 0.0f)), "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0," "\"stops\":[" "[{\"zoom\":0.0,\"value\":0.0},1.0]," - "[{\"zoom\":1.0,\"value\":0.0},1.0]]}"); + "[{\"zoom\":1.0,\"value\":0.0},1.0]],\"default\":0.0}"); } TEST(Stringify, PropertyValue) { diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp new file mode 100644 index 0000000000..260620c8d0 --- /dev/null +++ b/test/style/function/source_function.test.cpp @@ -0,0 +1,94 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/stub_geometry_tile_feature.hpp> + +#include <mbgl/style/function/source_function.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 }} +}; + +static StubGeometryTileFeature red { + PropertyMap {{ "property", "red"s }} +}; + +static StubGeometryTileFeature oneTwoInteger { + PropertyMap {{ "property", std::vector<Value>({uint64_t(1), uint64_t(2)}) }} +}; + +static StubGeometryTileFeature oneTwoDouble { + PropertyMap {{ "property", std::vector<Value>({1.0, 2.0}) }} +}; + +static StubGeometryTileFeature oneTwoString { + PropertyMap {{ "property", std::vector<Value>({"1"s, "2"s}) }} +}; + +static StubGeometryTileFeature trueFeature { + PropertyMap {{ "property", true }} +}; + +static StubGeometryTileFeature falseFeature { + PropertyMap {{ "property", false }} +}; + +TEST(SourceFunction, Identity) { + EXPECT_EQ(1.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f) + .evaluate(oneInteger, 2.0f)); + EXPECT_EQ(1.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f) + .evaluate(oneDouble, 2.0f)); + EXPECT_EQ(0.0f, SourceFunction<float>("property", IdentityStops<float>(), 0.0f) + .evaluate(oneString, 2.0f)); + EXPECT_EQ(2.0f, SourceFunction<float>("property", IdentityStops<float>()) + .evaluate(oneString, 2.0f)); + + EXPECT_EQ(Color::red(), SourceFunction<Color>("property", IdentityStops<Color>(), Color::black()) + .evaluate(red, Color::black())); + EXPECT_EQ(Color::black(), SourceFunction<Color>("property", IdentityStops<Color>(), Color::black()) + .evaluate(oneInteger, Color::black())); + + std::array<float, 2> zeroArray {{ 0, 0 }}; + EXPECT_EQ((std::array<float, 2> {{ 1, 2 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray) + .evaluate(oneTwoInteger, zeroArray))); + EXPECT_EQ((std::array<float, 2> {{ 1, 2 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray) + .evaluate(oneTwoDouble, zeroArray))); + EXPECT_EQ((std::array<float, 2> {{ 0, 0 }}), (SourceFunction<std::array<float, 2>>("property", IdentityStops<std::array<float, 2>>(), zeroArray) + .evaluate(oneTwoString, zeroArray))); +} + +TEST(SourceFunction, Categorical) { + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }})) + .evaluate(oneInteger, 0.0f)); + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }})) + .evaluate(oneDouble, 0.0f)); + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }})) + .evaluate(oneString, 0.0f)); + + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + .evaluate(oneInteger, 0.0f)); + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + .evaluate(oneDouble, 0.0f)); + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + .evaluate(oneString, 0.0f)); + + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ true, 1.0f }})) + .evaluate(trueFeature, 0.0f)); + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ true, 1.0f }})) + .evaluate(falseFeature, 0.0f)); + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ false, 1.0f }})) + .evaluate(trueFeature, 0.0f)); + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ false, 1.0f }})) + .evaluate(falseFeature, 0.0f)); +} |