Commit 9850fe18 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Test all but one line in animation.dart (#4751)

The one line we don't test is the private constructor for the Curves class,
which exists to ensure that no one constructs the Curves class.
parent b00efda7
......@@ -2,6 +2,8 @@
// 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';
......@@ -31,4 +33,62 @@ void main() {
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) {
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));
});
}
// 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 'package:flutter_test/flutter_test.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
void main() {
test('copyWith defaults to unchanged values', () {
SpringForce force = kDefaultSpringForce.copyWith();
expect(force.spring, kDefaultSpringForce.spring);
expect(force.left, kDefaultSpringForce.left);
expect(force.right, kDefaultSpringForce.right);
});
}
// 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 'package:flutter_test/flutter_test.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
void main() {
test('Can chain tweens', () {
Tween<double> tween = new Tween<double>(begin: 0.30, end: 0.50);
expect(tween, hasOneLineDescription);
Animatable<double> chain = tween.chain(new Tween<double>(begin: 0.50, end: 1.0));
AnimationController controller = new AnimationController();
expect(chain.evaluate(controller), 0.40);
expect(chain, hasOneLineDescription);
});
test('Can animated tweens', () {
Tween<double> tween = new Tween<double>(begin: 0.30, end: 0.50);
AnimationController controller = new AnimationController();
Animation<double> animation = tween.animate(controller);
controller.value = 0.50;
expect(animation.value, 0.40);
expect(animation, hasOneLineDescription);
expect(animation.toStringDetails(), hasOneLineDescription);
});
test('SizeTween', () {
SizeTween tween = new SizeTween(begin: Size.zero, end: new Size(20.0, 30.0));
expect(tween.lerp(0.5), equals(new Size(10.0, 15.0)));
expect(tween, hasOneLineDescription);
});
test('IntTween', () {
IntTween tween = new IntTween(begin: 5, end: 9);
expect(tween.lerp(0.5), 7);
expect(tween.lerp(0.7), 8);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment