Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SpringAnimationTest.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 <cmath>
6#import "flutter/third_party/spring_animation/spring_animation.h"
7#include "gtest/gtest.h"
8
9TEST(SpringAnimationTest, CanInitializeCorrectly) {
10 SpringAnimation* animation = [[SpringAnimation alloc] initWithStiffness:1000
11 damping:500
12 mass:3
13 initialVelocity:0
14 fromValue:0
15 toValue:1000];
16 ASSERT_TRUE(animation.stiffness == 1000);
17 ASSERT_TRUE(animation.damping == 500);
18 ASSERT_TRUE(animation.mass == 3);
19 ASSERT_TRUE(animation.initialVelocity == 0);
20 ASSERT_TRUE(animation.fromValue == 0);
21 ASSERT_TRUE(animation.toValue == 1000);
22}
23
24TEST(SpringAnimationTest, CurveFunctionCanWorkCorrectly) {
25 // Here is the keyboard curve config on iOS platform.
26 SpringAnimation* animation = [[SpringAnimation alloc] initWithStiffness:1000
27 damping:500
28 mass:3
29 initialVelocity:0
30 fromValue:0
31 toValue:1000];
32 const double accuracy = 1.0;
33 const double startTime = 0;
34 const double endTime = 0.6;
35
36 const double startValue = [animation curveFunction:startTime];
37 ASSERT_TRUE(fabs(startValue - animation.fromValue) < accuracy);
38 const double toValue = [animation curveFunction:endTime];
39 ASSERT_TRUE(fabs(toValue - animation.toValue) < accuracy);
40}
41
42TEST(SpringAnimationTest, CanUpdatePositionValuesAndCalculateCorrectly) {
43 SpringAnimation* animation = [[SpringAnimation alloc] initWithStiffness:1000
44 damping:500
45 mass:3
46 initialVelocity:0
47 fromValue:0
48 toValue:1000];
49 const double startTime = 0;
50 const double endTime = 0.6;
51
52 const double startValue1 = [animation curveFunction:startTime];
53 const double toValue1 = [animation curveFunction:endTime];
54
55 animation.fromValue = 10;
56 animation.toValue = 800;
57
58 ASSERT_TRUE(animation.fromValue == 10);
59 ASSERT_TRUE(animation.toValue == 800);
60
61 const double startValue2 = [animation curveFunction:startTime];
62 const double toValue2 = [animation curveFunction:endTime];
63 ASSERT_TRUE(startValue2 > startValue1);
64 ASSERT_TRUE(toValue2 < toValue1);
65}
#define TEST(S, s, D, expected)