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

Side by Side 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: Created 6 years, 9 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 unified diff | Download patch
« no previous file with comments | « Source/core/animation/InterpolableValue.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/animation/InterpolableValue.h"
7
8 #include <gtest/gtest.h>
9
10 namespace WebCore {
11
12 class AnimationInterpolableValueTest : public ::testing::Test {
13 protected:
14 double interpolateNumbers(double a, double b, double progress)
15 {
16 OwnPtr<InterpolableValue> aVal = static_pointer_cast<InterpolableValue>( InterpolableNumber::create(a));
17 return toInterpolableNumber(aVal->interpolate(*InterpolableNumber::creat e(b).get(), progress).get())->value();
18 }
19
20 double interpolateBools(bool a, bool b, double progress)
21 {
22 OwnPtr<InterpolableValue> aVal = static_pointer_cast<InterpolableValue>( InterpolableBool::create(a));
23 return toInterpolableBool(aVal->interpolate(*InterpolableBool::create(b) .get(), progress).get())->value();
24 }
25
26 PassOwnPtr<InterpolableValue> interpolateLists(PassOwnPtr<InterpolableList> listA, PassOwnPtr<InterpolableList> listB, double progress)
27 {
28 return static_pointer_cast<InterpolableValue>(listA)->interpolate(*listB .get(), progress);
29 }
30 };
31
32 TEST_F(AnimationInterpolableValueTest, InterpolateNumbers)
33 {
34 EXPECT_FLOAT_EQ(126, interpolateNumbers(42, 0, -2));
35 EXPECT_FLOAT_EQ(42, interpolateNumbers(42, 0, 0));
36 EXPECT_FLOAT_EQ(29.4f, interpolateNumbers(42, 0, 0.3));
37 EXPECT_FLOAT_EQ(21, interpolateNumbers(42, 0, 0.5));
38 EXPECT_FLOAT_EQ(0, interpolateNumbers(42, 0, 1));
39 EXPECT_FLOAT_EQ(-21, interpolateNumbers(42, 0, 1.5));
40 }
41
42 TEST_F(AnimationInterpolableValueTest, InterpolateBools)
43 {
44 EXPECT_FALSE(interpolateBools(false, true, -1));
45 EXPECT_FALSE(interpolateBools(false, true, 0));
46 EXPECT_FALSE(interpolateBools(false, true, 0.3));
47 EXPECT_TRUE(interpolateBools(false, true, 0.5));
48 EXPECT_TRUE(interpolateBools(false, true, 1));
49 EXPECT_TRUE(interpolateBools(false, true, 2));
50 }
51
52 TEST_F(AnimationInterpolableValueTest, SimpleList)
53 {
54 OwnPtr<InterpolableList> listA = InterpolableList::create(3);
55 listA->set(0, InterpolableNumber::create(0));
56 listA->set(1, InterpolableNumber::create(42));
57 listA->set(2, InterpolableNumber::create(20.5));
58
59 OwnPtr<InterpolableList> listB = InterpolableList::create(3);
60 listB->set(0, InterpolableNumber::create(100));
61 listB->set(1, InterpolableNumber::create(-200));
62 listB->set(2, InterpolableNumber::create(300));
63
64 OwnPtr<InterpolableValue> result = interpolateLists(listA.release(), listB.r elease(), 0.3);
65 InterpolableList* outList = toInterpolableList(result.get());
66 EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value());
67 EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value());
68 EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value());
69 }
70
71 TEST_F(AnimationInterpolableValueTest, NestedList)
72 {
73 OwnPtr<InterpolableList> listA = InterpolableList::create(3);
74 listA->set(0, InterpolableNumber::create(0));
75 OwnPtr<InterpolableList> subListA = InterpolableList::create(1);
76 subListA->set(0, InterpolableNumber::create(100));
77 listA->set(1, subListA.release());
78 listA->set(2, InterpolableBool::create(false));
79
80 OwnPtr<InterpolableList> listB = InterpolableList::create(3);
81 listB->set(0, InterpolableNumber::create(100));
82 OwnPtr<InterpolableList> subListB = InterpolableList::create(1);
83 subListB->set(0, InterpolableNumber::create(50));
84 listB->set(1, subListB.release());
85 listB->set(2, InterpolableBool::create(true));
86
87 OwnPtr<InterpolableValue> result = interpolateLists(listA.release(), listB.r elease(), 0.5);
88 InterpolableList* outList = toInterpolableList(result.get());
89 EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value());
90 EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList->get(1)) ->get(0))->value());
91 EXPECT_TRUE(toInterpolableBool(outList->get(2))->value());
92 }
93
94 }
OLDNEW
« no previous file with comments | « Source/core/animation/InterpolableValue.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698