1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2016 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.
import 'dart:math' as math;
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
void main() {
test('toString control test', () {
expect(Curves.linear, hasOneLineDescription);
expect(const SawTooth(3), hasOneLineDescription);
expect(const Interval(0.25, 0.75), hasOneLineDescription);
expect(const Interval(0.25, 0.75, curve: Curves.ease), hasOneLineDescription);
});
test('Curve flipped control test', () {
final Curve ease = Curves.ease;
final Curve flippedEase = ease.flipped;
expect(flippedEase.transform(0.0), lessThan(0.001));
expect(flippedEase.transform(0.5), lessThan(ease.transform(0.5)));
expect(flippedEase.transform(1.0), greaterThan(0.999));
expect(flippedEase, hasOneLineDescription);
});
test('Threshold has a threshold', () {
final Curve step = const Threshold(0.25);
expect(step.transform(0.0), 0.0);
expect(step.transform(0.24), 0.0);
expect(step.transform(0.25), 1.0);
expect(step.transform(0.26), 1.0);
expect(step.transform(1.0), 1.0);
});
void expectStaysInBounds(Curve curve) {
expect(curve.transform(0.0), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.1), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.2), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.3), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.4), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.5), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.6), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.7), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.8), inInclusiveRange(0.0, 1.0));
expect(curve.transform(0.9), inInclusiveRange(0.0, 1.0));
expect(curve.transform(1.0), inInclusiveRange(0.0, 1.0));
}
test('Bounce stays in bounds', () {
expectStaysInBounds(Curves.bounceIn);
expectStaysInBounds(Curves.bounceOut);
expectStaysInBounds(Curves.bounceInOut);
});
List<double> estimateBounds(Curve curve) {
final List<double> values = <double>[];
values.add(curve.transform(0.0));
values.add(curve.transform(0.1));
values.add(curve.transform(0.2));
values.add(curve.transform(0.3));
values.add(curve.transform(0.4));
values.add(curve.transform(0.5));
values.add(curve.transform(0.6));
values.add(curve.transform(0.7));
values.add(curve.transform(0.8));
values.add(curve.transform(0.9));
values.add(curve.transform(1.0));
return <double>[
values.reduce(math.min),
values.reduce(math.max),
];
}
test('Ellastic overshoots its bounds', () {
expect(Curves.elasticIn, hasOneLineDescription);
expect(Curves.elasticOut, hasOneLineDescription);
expect(Curves.elasticInOut, hasOneLineDescription);
List<double> bounds;
bounds = estimateBounds(Curves.elasticIn);
expect(bounds[0], lessThan(0.0));
expect(bounds[1], lessThanOrEqualTo(1.0));
bounds = estimateBounds(Curves.elasticOut);
expect(bounds[0], greaterThanOrEqualTo(0.0));
expect(bounds[1], greaterThan(1.0));
bounds = estimateBounds(Curves.elasticInOut);
expect(bounds[0], lessThan(0.0));
expect(bounds[1], greaterThan(1.0));
});
test('Decelerate does so', () {
expect(Curves.decelerate, hasOneLineDescription);
final List<double> bounds = estimateBounds(Curves.decelerate);
expect(bounds[0], greaterThanOrEqualTo(0.0));
expect(bounds[1], lessThanOrEqualTo(1.0));
final double d1 = Curves.decelerate.transform(0.2) - Curves.decelerate.transform(0.0);
final double d2 = Curves.decelerate.transform(1.0) - Curves.decelerate.transform(0.8);
expect(d2, lessThan(d1));
});
test('Invalid transform parameter should assert', () {
expect(() => const SawTooth(2).transform(-0.0001), throwsAssertionError);
expect(() => const SawTooth(2).transform(1.0001), throwsAssertionError);
expect(() => const Interval(0.0, 1.0).transform(-0.0001), throwsAssertionError);
expect(() => const Interval(0.0, 1.0).transform(1.0001), throwsAssertionError);
expect(() => const Threshold(0.5).transform(-0.0001), throwsAssertionError);
expect(() => const Threshold(0.5).transform(1.0001), throwsAssertionError);
expect(() => const ElasticInCurve().transform(-0.0001), throwsAssertionError);
expect(() => const ElasticInCurve().transform(1.0001), throwsAssertionError);
expect(() => const ElasticOutCurve().transform(-0.0001), throwsAssertionError);
expect(() => const ElasticOutCurve().transform(1.0001), throwsAssertionError);
expect(() => const Cubic(0.42, 0.0, 0.58, 1.0).transform(-0.0001), throwsAssertionError);
expect(() => const Cubic(0.42, 0.0, 0.58, 1.0).transform(1.0001), throwsAssertionError);
expect(() => Curves.decelerate.transform(-0.0001), throwsAssertionError);
expect(() => Curves.decelerate.transform(1.0001), throwsAssertionError);
expect(() => Curves.bounceIn.transform(-0.0001), throwsAssertionError);
expect(() => Curves.bounceIn.transform(1.0001), throwsAssertionError);
expect(() => Curves.bounceOut.transform(-0.0001), throwsAssertionError);
expect(() => Curves.bounceOut.transform(1.0001), throwsAssertionError);
expect(() => Curves.bounceInOut.transform(-0.0001), throwsAssertionError);
expect(() => Curves.bounceInOut.transform(1.0001), throwsAssertionError);
});
}