diff --git a/packages/flutter/test/animation/curves_test.dart b/packages/flutter/test/animation/curves_test.dart index e99c51b4cd..ce18745732 100644 --- a/packages/flutter/test/animation/curves_test.dart +++ b/packages/flutter/test/animation/curves_test.dart @@ -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 estimateBounds(Curve curve) { + List values = []; + + 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 [ + 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 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)); + }); } diff --git a/packages/flutter/test/animation/forces_test.dart b/packages/flutter/test/animation/forces_test.dart new file mode 100644 index 0000000000..bf5d104c77 --- /dev/null +++ b/packages/flutter/test/animation/forces_test.dart @@ -0,0 +1,16 @@ +// 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); + }); +} diff --git a/packages/flutter/test/animation/tween_test.dart b/packages/flutter/test/animation/tween_test.dart new file mode 100644 index 0000000000..c6f44c2e85 --- /dev/null +++ b/packages/flutter/test/animation/tween_test.dart @@ -0,0 +1,40 @@ +// 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 tween = new Tween(begin: 0.30, end: 0.50); + expect(tween, hasOneLineDescription); + Animatable chain = tween.chain(new Tween(begin: 0.50, end: 1.0)); + AnimationController controller = new AnimationController(); + expect(chain.evaluate(controller), 0.40); + expect(chain, hasOneLineDescription); + }); + + test('Can animated tweens', () { + Tween tween = new Tween(begin: 0.30, end: 0.50); + AnimationController controller = new AnimationController(); + Animation 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); + }); +}