summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-25 13:59:09 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-02 14:51:39 -0700
commitcadc617c762d453cca2c9bac41f9c1db984c5fac (patch)
tree5a15363a54ef81b0106693dd83c70bfdf7761393 /test
parentba4a8a97316d65ab595bb7edf759f463bbd10049 (diff)
downloadqtlocation-mapboxgl-cadc617c762d453cca2c9bac41f9c1db984c5fac.tar.gz
[core] Introduce PropertyValue<T>
PropertyValue<T> represents the three possible types of style property value: undefined, constant, or function.
Diffstat (limited to 'test')
-rw-r--r--test/style/functions.cpp75
1 files changed, 38 insertions, 37 deletions
diff --git a/test/style/functions.cpp b/test/style/functions.cpp
index 586941ecf0..8812c77b55 100644
--- a/test/style/functions.cpp
+++ b/test/style/functions.cpp
@@ -1,62 +1,63 @@
#include <iostream>
#include <mbgl/test/util.hpp>
-#include <mbgl/style/function_evaluator.hpp>
+#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/style/style_calculation_parameters.hpp>
using namespace mbgl;
+float evaluate(PropertyValue<float> value, float zoom) {
+ return PropertyValue<float>::visit(value, PropertyEvaluator<float>(StyleCalculationParameters(zoom), 0));
+}
+
TEST(Function, Constant) {
- NormalFunctionEvaluator<float> evaluate;
- EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(0)));
- EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(0)));
- EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(0)));
- EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(4)));
- EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(4)));
- EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(4)));
- EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(22)));
- EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(22)));
- EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(22)));
+ EXPECT_EQ(2.0f, evaluate(2, 0));
+ EXPECT_EQ(3.8f, evaluate(3.8, 0));
+ EXPECT_EQ(22.0f, evaluate(22, 0));
+ EXPECT_EQ(2.0f, evaluate(2, 4));
+ EXPECT_EQ(3.8f, evaluate(3.8, 4));
+ EXPECT_EQ(22.0f, evaluate(22, 4));
+ EXPECT_EQ(2.0f, evaluate(2, 22));
+ EXPECT_EQ(3.8f, evaluate(3.8, 22));
+ EXPECT_EQ(22.0f, evaluate(22, 22));
}
TEST(Function, Stops) {
- NormalFunctionEvaluator<float> evaluate;
-
// Explicit constant slope in fringe regions.
Function<float> slope_1({ { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75);
- EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(0)));
- EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(4)));
- EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(6)));
- ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, StyleCalculationParameters(7)));
- EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(8)));
- EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(9)));
- EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(15)));
- EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(22)));
+ 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.
Function<float> slope_2({ { 6, 1.5 }, { 8, 3 } }, 1.75);
- EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(0)));
- EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(4)));
- EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(6)));
- ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, StyleCalculationParameters(7)));
- EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(8)));
- EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(9)));
- EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(15)));
- EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(22)));
+ 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));
// Test no values.
Function<float> slope_3({}, 1.75);
- EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(2)));
- EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(6)));
- EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(12)));
+ EXPECT_EQ(1, evaluate(slope_3, 2));
+ EXPECT_EQ(1, evaluate(slope_3, 6));
+ EXPECT_EQ(1, evaluate(slope_3, 12));
// Explicit constant slope in fringe regions.
Function<float> slope_4({ { 0, 2 }, { 8, 10 } }, 1);
- EXPECT_EQ(2, evaluate(slope_4, StyleCalculationParameters(0)));
- EXPECT_EQ(3, evaluate(slope_4, StyleCalculationParameters(1)));
- EXPECT_EQ(4, evaluate(slope_4, StyleCalculationParameters(2)));
- EXPECT_EQ(4.75, evaluate(slope_4, StyleCalculationParameters(2.75)));
- EXPECT_EQ(10, evaluate(slope_4, StyleCalculationParameters(8)));
+ 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));
}