| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/geometry/cubic_bezier.h" | 5 #include "ui/gfx/geometry/cubic_bezier.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace gfx { | 11 namespace gfx { |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 TEST(CubicBezierTest, Basic) { | 14 TEST(CubicBezierTest, Basic) { |
| 14 CubicBezier function(0.25, 0.0, 0.75, 1.0); | 15 CubicBezier function(0.25, 0.0, 0.75, 1.0); |
| 15 | 16 |
| 16 double epsilon = 0.00015; | 17 double epsilon = 0.00015; |
| 17 | 18 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 EXPECT_NEAR(function.Solve(0.9), 1.15613, epsilon); | 74 EXPECT_NEAR(function.Solve(0.9), 1.15613, epsilon); |
| 74 EXPECT_NEAR(function.Solve(0.95), 1.08954, epsilon); | 75 EXPECT_NEAR(function.Solve(0.95), 1.08954, epsilon); |
| 75 EXPECT_NEAR(function.Solve(1.0), 1.0, epsilon); | 76 EXPECT_NEAR(function.Solve(1.0), 1.0, epsilon); |
| 76 } | 77 } |
| 77 | 78 |
| 78 TEST(CubicBezierTest, Range) { | 79 TEST(CubicBezierTest, Range) { |
| 79 double epsilon = 0.00015; | 80 double epsilon = 0.00015; |
| 80 double min, max; | 81 double min, max; |
| 81 | 82 |
| 82 // Derivative is a constant. | 83 // Derivative is a constant. |
| 83 scoped_ptr<CubicBezier> function( | 84 std::unique_ptr<CubicBezier> function( |
| 84 new CubicBezier(0.25, (1.0 / 3.0), 0.75, (2.0 / 3.0))); | 85 new CubicBezier(0.25, (1.0 / 3.0), 0.75, (2.0 / 3.0))); |
| 85 function->Range(&min, &max); | 86 function->Range(&min, &max); |
| 86 EXPECT_EQ(0, min); | 87 EXPECT_EQ(0, min); |
| 87 EXPECT_EQ(1, max); | 88 EXPECT_EQ(1, max); |
| 88 | 89 |
| 89 // Derivative is linear. | 90 // Derivative is linear. |
| 90 function.reset(new CubicBezier(0.25, -0.5, 0.75, (-1.0 / 6.0))); | 91 function.reset(new CubicBezier(0.25, -0.5, 0.75, (-1.0 / 6.0))); |
| 91 function->Range(&min, &max); | 92 function->Range(&min, &max); |
| 92 EXPECT_NEAR(min, -0.225, epsilon); | 93 EXPECT_NEAR(min, -0.225, epsilon); |
| 93 EXPECT_EQ(1, max); | 94 EXPECT_EQ(1, max); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 EXPECT_EQ(2.0, coincident_endpoint.Solve(2.0)); | 206 EXPECT_EQ(2.0, coincident_endpoint.Solve(2.0)); |
| 206 | 207 |
| 207 CubicBezier three_coincident_points(0.0, 0.0, 0.0, 0.0); | 208 CubicBezier three_coincident_points(0.0, 0.0, 0.0, 0.0); |
| 208 EXPECT_EQ(0, three_coincident_points.Solve(-1.0)); | 209 EXPECT_EQ(0, three_coincident_points.Solve(-1.0)); |
| 209 EXPECT_EQ(2.0, three_coincident_points.Solve(2.0)); | 210 EXPECT_EQ(2.0, three_coincident_points.Solve(2.0)); |
| 210 | 211 |
| 211 } | 212 } |
| 212 | 213 |
| 213 } // namespace | 214 } // namespace |
| 214 } // namespace gfx | 215 } // namespace gfx |
| OLD | NEW |