Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Unified Diff: Source/core/animation/InterpolableValueTest.cpp

Issue 177183007: Web Animations: Add InterpolableValue hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added unit tests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/animation/InterpolableValueTest.cpp
diff --git a/Source/core/animation/InterpolableValueTest.cpp b/Source/core/animation/InterpolableValueTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..aa8c730df4c965e5979e01162ae2eb06915f46ec
--- /dev/null
+++ b/Source/core/animation/InterpolableValueTest.cpp
@@ -0,0 +1,88 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/animation/InterpolableValue.h"
+
+#include <gtest/gtest.h>
+
+namespace WebCore {
+
+namespace {
+
+double interpolateNumbers(double a, double b, double progress)
+{
+ return toInterpolableNumber(InterpolableNumber::create(a)->interpolate(*InterpolableNumber::create(b).get(), progress).get())->value();
+}
+
+double interpolateBools(bool a, bool b, double progress)
+{
+ return toInterpolableBool(InterpolableBool::create(a)->interpolate(*InterpolableBool::create(b).get(), progress).get())->value();
+}
+
+}
+
+TEST(AnimationInterpolableValueTest, InterpolateNumbers)
+{
+ EXPECT_FLOAT_EQ(126, interpolateNumbers(42, 0, -2));
+ EXPECT_FLOAT_EQ(42, interpolateNumbers(42, 0, 0));
+ EXPECT_FLOAT_EQ(29.4, interpolateNumbers(42, 0, 0.3));
+ EXPECT_FLOAT_EQ(21, interpolateNumbers(42, 0, 0.5));
+ EXPECT_FLOAT_EQ(0, interpolateNumbers(42, 0, 1));
+ EXPECT_FLOAT_EQ(-21, interpolateNumbers(42, 0, 1.5));
+}
+
+TEST(AnimationInterpolableValueTest, InterpolateBools)
+{
+ EXPECT_FALSE(interpolateBools(false, true, -1));
+ EXPECT_FALSE(interpolateBools(false, true, 0));
+ EXPECT_FALSE(interpolateBools(false, true, 0.3));
+ EXPECT_TRUE(interpolateBools(false, true, 0.5));
+ EXPECT_TRUE(interpolateBools(false, true, 1));
+ EXPECT_TRUE(interpolateBools(false, true, 2));
+}
+
+TEST(AnimationInterpolableValueTest, SimpleList)
+{
+ OwnPtr<InterpolableList> listA = InterpolableList::create(3);
+ listA->set(0, InterpolableNumber::create(0));
+ listA->set(1, InterpolableNumber::create(42));
+ listA->set(2, InterpolableNumber::create(20.5));
+
+ OwnPtr<InterpolableList> listB = InterpolableList::create(3);
+ listB->set(0, InterpolableNumber::create(100));
+ listB->set(1, InterpolableNumber::create(-200));
+ listB->set(2, InterpolableNumber::create(300));
+
+ OwnPtr<InterpolableValue> result = listA->interpolate(*listB.get(), 0.3);
+ InterpolableList* outList = toInterpolableList(result.get());
+ EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value());
+ EXPECT_FLOAT_EQ(-30.6, toInterpolableNumber(outList->get(1))->value());
+ EXPECT_FLOAT_EQ(104.35, toInterpolableNumber(outList->get(2))->value());
alancutter (OOO until 2018) 2014/02/26 00:42:29 Should these list tests be testing more than one i
shans 2014/02/26 21:24:20 As discussed, this is sufficient.
+}
+
+TEST(AnimationInterpolableValueTest, NestedList)
+{
+ OwnPtr<InterpolableList> listA = InterpolableList::create(3);
+ listA->set(0, InterpolableNumber::create(0));
+ OwnPtr<InterpolableList> subListA = InterpolableList::create(1);
+ subListA->set(0, InterpolableNumber::create(100));
+ listA->set(1, subListA.release());
+ listA->set(2, InterpolableBool::create(false));
+
+ OwnPtr<InterpolableList> listB = InterpolableList::create(3);
+ listB->set(0, InterpolableNumber::create(100));
+ OwnPtr<InterpolableList> subListB = InterpolableList::create(1);
+ subListB->set(0, InterpolableNumber::create(50));
+ listB->set(1, subListB.release());
+ listB->set(2, InterpolableBool::create(true));
+
+ OwnPtr<InterpolableValue> result = listA->interpolate(*listB.get(), 0.5);
+ InterpolableList* outList = toInterpolableList(result.get());
+ EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value());
+ EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0))->value());
+ EXPECT_TRUE(toInterpolableBool(outList->get(2))->value());
alancutter (OOO until 2018) 2014/02/26 00:42:29 Overloading [] might make this cleaner here and in
shans 2014/02/26 21:24:20 I don't think it is worth it, as InterpolableValue
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698