Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / animation / UnitBezierTest.cpp
blob0ddc6ee81df9f52feba7a58a47f2106229ba0b45
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "config.h"
26 #include "platform/animation/UnitBezier.h"
28 #include <gtest/gtest.h>
30 namespace blink {
32 TEST(UnitBezierTest, BasicUse)
34 UnitBezier bezier(0.5, 1.0, 0.5, 1.0);
35 EXPECT_EQ(0.875, bezier.solve(0.5, 0.005));
38 TEST(UnitBezierTest, Overshoot)
40 UnitBezier bezier(0.5, 2.0, 0.5, 2.0);
41 EXPECT_EQ(1.625, bezier.solve(0.5, 0.005));
44 TEST(UnitBezierTest, Undershoot)
46 UnitBezier bezier(0.5, -1.0, 0.5, -1.0);
47 EXPECT_EQ(-0.625, bezier.solve(0.5, 0.005));
50 TEST(UnitBezierTest, InputAtEdgeOfRange)
52 UnitBezier bezier(0.5, 1.0, 0.5, 1.0);
53 EXPECT_EQ(0.0, bezier.solve(0.0, 0.005));
54 EXPECT_EQ(1.0, bezier.solve(1.0, 0.005));
57 TEST(UnitBezierTest, InputOutOfRange)
59 UnitBezier bezier(0.5, 1.0, 0.5, 1.0);
60 EXPECT_EQ(-2.0, bezier.solve(-1.0, 0.005));
61 EXPECT_EQ(1.0, bezier.solve(2.0, 0.005));
64 TEST(UnitBezierTest, InputOutOfRangeLargeEpsilon)
66 UnitBezier bezier(0.5, 1.0, 0.5, 1.0);
67 EXPECT_EQ(-2.0, bezier.solve(-1.0, 1.0));
68 EXPECT_EQ(1.0, bezier.solve(2.0, 1.0));
71 TEST(UnitBezierTest, InputOutOfRangeCoincidentEndpoints)
73 UnitBezier bezier(0.0, 0.0, 1.0, 1.0);
74 EXPECT_EQ(-1.0, bezier.solve(-1.0, 0.005));
75 EXPECT_EQ(2.0, bezier.solve(2.0, 0.005));
78 TEST(UnitBezierTest, InputOutOfRangeVerticalGradient)
80 UnitBezier bezier(0.0, 1.0, 1.0, 0.0);
81 EXPECT_EQ(0.0, bezier.solve(-1.0, 0.005));
82 EXPECT_EQ(1.0, bezier.solve(2.0, 0.005));
85 TEST(UnitBezierTest, InputOutOfRangeDistinctEndpoints)
87 UnitBezier bezier(0.1, 0.2, 0.8, 0.8);
88 EXPECT_EQ(-2.0, bezier.solve(-1.0, 0.005));
89 EXPECT_EQ(2.0, bezier.solve(2.0, 0.005));
92 } // namespace blink