diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-01-17 11:48:37 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-01-17 15:18:14 -0600 |
commit | 531a1c3070a098b5b31082c0500f0a3ce6a500bb (patch) | |
tree | dc01f3f1b164fc564624d498aea02b6c42576cd8 /test | |
parent | b04e11b5ca377e288b9ad27406603e4e1076a375 (diff) | |
download | qtlocation-mapboxgl-531a1c3070a098b5b31082c0500f0a3ce6a500bb.tar.gz |
[core] Fix calculation of delayed transitions
Diffstat (limited to 'test')
-rw-r--r-- | test/style/paint_property.test.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/style/paint_property.test.cpp b/test/style/paint_property.test.cpp new file mode 100644 index 0000000000..487dbe9652 --- /dev/null +++ b/test/style/paint_property.test.cpp @@ -0,0 +1,94 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/style/paint_property.hpp> + +using namespace mbgl; +using namespace mbgl::style; +using namespace std::literals::chrono_literals; + +TEST(UnevaluatedPaintProperty, EvaluateDefaultValue) { + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> property; + ASSERT_EQ(0.0f, property.evaluate(PropertyEvaluationParameters(0), 0.0f)); +} + +TEST(UnevaluatedPaintProperty, EvaluateUntransitionedConstant) { + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> property { + PropertyValue<float>(1.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + ASSERT_EQ(1.0f, property.evaluate(PropertyEvaluationParameters(0), 0.0f)); +} + +TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithoutDelay) { + TransitionOptions transition; + transition.duration = { 1000ms }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t0 { + PropertyValue<float>(0.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t1 { + PropertyValue<float>(1.0f), + t0, + transition, + TimePoint::min() + }; + + auto evaluate = [&] (Duration delta) { + PropertyEvaluationParameters parameters { + 0, + TimePoint::min() + delta, + ZoomHistory(), + Duration::zero() + }; + + return t1.evaluate(parameters, 0.0f); + }; + + ASSERT_FLOAT_EQ(0.0f, evaluate(0ms)); + ASSERT_FLOAT_EQ(0.823099f, evaluate(500ms)); + ASSERT_FLOAT_EQ(1.0f, evaluate(1500ms)); +} + +TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithDelay) { + TransitionOptions transition; + transition.delay = { 1000ms }; + transition.duration = { 1000ms }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t0 { + PropertyValue<float>(0.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t1 { + PropertyValue<float>(1.0f), + t0, + transition, + TimePoint::min() + }; + + auto evaluate = [&] (Duration delta) { + PropertyEvaluationParameters parameters { + 0, + TimePoint::min() + delta, + ZoomHistory(), + Duration::zero() + }; + + return t1.evaluate(parameters, 0.0f); + }; + + ASSERT_FLOAT_EQ(0.0f, evaluate(0ms)); + ASSERT_FLOAT_EQ(0.0f, evaluate(500ms)); + ASSERT_FLOAT_EQ(0.0f, evaluate(612ms)); + ASSERT_FLOAT_EQ(0.823099f, evaluate(1500ms)); + ASSERT_FLOAT_EQ(1.0f, evaluate(2500ms)); +} |