Unverified Commit c935a448 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Prefer moreOrLessEquals to closeTo (#64914)

moreOrLessEquals is the preferred mechanism for checking that a value is
within some error bound epsilon, with default value for epsilon of
precisionErrorTolerance.

This patch replaces instances of closeTo using precisionErrorTolerance.
parent 69f40ebe
...@@ -153,25 +153,25 @@ void main() { ...@@ -153,25 +153,25 @@ void main() {
controller.forward(); controller.forward();
tick(const Duration(milliseconds: 10)); tick(const Duration(milliseconds: 10));
tick(const Duration(milliseconds: 30)); tick(const Duration(milliseconds: 30));
expect(controller.value, closeTo(0.2, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.2));
tick(const Duration(milliseconds: 60)); tick(const Duration(milliseconds: 60));
expect(controller.value, closeTo(0.5, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.5));
tick(const Duration(milliseconds: 90)); tick(const Duration(milliseconds: 90));
expect(controller.value, closeTo(0.8, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 120)); tick(const Duration(milliseconds: 120));
expect(controller.value, closeTo(1.0, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(1.0));
controller.stop(); controller.stop();
controller.reverse(); controller.reverse();
tick(const Duration(milliseconds: 210)); tick(const Duration(milliseconds: 210));
tick(const Duration(milliseconds: 220)); tick(const Duration(milliseconds: 220));
expect(controller.value, closeTo(0.8, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 230)); tick(const Duration(milliseconds: 230));
expect(controller.value, closeTo(0.6, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.6));
tick(const Duration(milliseconds: 240)); tick(const Duration(milliseconds: 240));
expect(controller.value, closeTo(0.4, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 260)); tick(const Duration(milliseconds: 260));
expect(controller.value, closeTo(0.0, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.0));
controller.stop(); controller.stop();
// Swap which duration is longer. // Swap which duration is longer.
...@@ -184,25 +184,25 @@ void main() { ...@@ -184,25 +184,25 @@ void main() {
controller.forward(); controller.forward();
tick(const Duration(milliseconds: 10)); tick(const Duration(milliseconds: 10));
tick(const Duration(milliseconds: 30)); tick(const Duration(milliseconds: 30));
expect(controller.value, closeTo(0.4, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 60)); tick(const Duration(milliseconds: 60));
expect(controller.value, closeTo(1.0, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(1.0));
tick(const Duration(milliseconds: 90)); tick(const Duration(milliseconds: 90));
expect(controller.value, closeTo(1.0, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(1.0));
controller.stop(); controller.stop();
controller.reverse(); controller.reverse();
tick(const Duration(milliseconds: 210)); tick(const Duration(milliseconds: 210));
tick(const Duration(milliseconds: 220)); tick(const Duration(milliseconds: 220));
expect(controller.value, closeTo(0.9, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.9));
tick(const Duration(milliseconds: 230)); tick(const Duration(milliseconds: 230));
expect(controller.value, closeTo(0.8, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 240)); tick(const Duration(milliseconds: 240));
expect(controller.value, closeTo(0.7, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.7));
tick(const Duration(milliseconds: 260)); tick(const Duration(milliseconds: 260));
expect(controller.value, closeTo(0.5, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.5));
tick(const Duration(milliseconds: 310)); tick(const Duration(milliseconds: 310));
expect(controller.value, closeTo(0.0, precisionErrorTolerance)); expect(controller.value, moreOrLessEquals(0.0));
controller.stop(); controller.stop();
}); });
......
...@@ -273,38 +273,38 @@ FlutterError ...@@ -273,38 +273,38 @@ FlutterError
controller.forward(); controller.forward();
tick(const Duration(milliseconds: 0)); tick(const Duration(milliseconds: 0));
tick(const Duration(milliseconds: 10)); tick(const Duration(milliseconds: 10));
expect(curved.value, closeTo(0.1, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.1));
tick(const Duration(milliseconds: 20)); tick(const Duration(milliseconds: 20));
expect(curved.value, closeTo(0.2, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.2));
tick(const Duration(milliseconds: 30)); tick(const Duration(milliseconds: 30));
expect(curved.value, closeTo(0.3, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.3));
tick(const Duration(milliseconds: 40)); tick(const Duration(milliseconds: 40));
expect(curved.value, closeTo(0.4, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 50)); tick(const Duration(milliseconds: 50));
expect(curved.value, closeTo(0.5, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.5));
tick(const Duration(milliseconds: 60)); tick(const Duration(milliseconds: 60));
expect(curved.value, closeTo(0.6, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.6));
tick(const Duration(milliseconds: 70)); tick(const Duration(milliseconds: 70));
expect(curved.value, closeTo(0.7, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.7));
tick(const Duration(milliseconds: 80)); tick(const Duration(milliseconds: 80));
expect(curved.value, closeTo(0.8, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 90)); tick(const Duration(milliseconds: 90));
expect(curved.value, closeTo(0.9, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.9));
tick(const Duration(milliseconds: 100)); tick(const Duration(milliseconds: 100));
expect(curved.value, closeTo(1.0, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(1.0));
controller.reverse(); controller.reverse();
tick(const Duration(milliseconds: 110)); tick(const Duration(milliseconds: 110));
expect(curved.value, closeTo(1.0, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(1.0));
tick(const Duration(milliseconds: 120)); tick(const Duration(milliseconds: 120));
expect(curved.value, closeTo(0.8, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 130)); tick(const Duration(milliseconds: 130));
expect(curved.value, closeTo(0.6, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.6));
tick(const Duration(milliseconds: 140)); tick(const Duration(milliseconds: 140));
expect(curved.value, closeTo(0.4, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 150)); tick(const Duration(milliseconds: 150));
expect(curved.value, closeTo(0.2, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.2));
tick(const Duration(milliseconds: 160)); tick(const Duration(milliseconds: 160));
expect(curved.value, closeTo(0.0, precisionErrorTolerance)); expect(curved.value, moreOrLessEquals(0.0));
}); });
test('ReverseAnimation running with different forward and reverse durations.', () { test('ReverseAnimation running with different forward and reverse durations.', () {
...@@ -324,38 +324,38 @@ FlutterError ...@@ -324,38 +324,38 @@ FlutterError
controller.forward(); controller.forward();
tick(const Duration(milliseconds: 0)); tick(const Duration(milliseconds: 0));
tick(const Duration(milliseconds: 10)); tick(const Duration(milliseconds: 10));
expect(reversed.value, closeTo(0.9, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.9));
tick(const Duration(milliseconds: 20)); tick(const Duration(milliseconds: 20));
expect(reversed.value, closeTo(0.8, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 30)); tick(const Duration(milliseconds: 30));
expect(reversed.value, closeTo(0.7, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.7));
tick(const Duration(milliseconds: 40)); tick(const Duration(milliseconds: 40));
expect(reversed.value, closeTo(0.6, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.6));
tick(const Duration(milliseconds: 50)); tick(const Duration(milliseconds: 50));
expect(reversed.value, closeTo(0.5, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.5));
tick(const Duration(milliseconds: 60)); tick(const Duration(milliseconds: 60));
expect(reversed.value, closeTo(0.4, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 70)); tick(const Duration(milliseconds: 70));
expect(reversed.value, closeTo(0.3, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.3));
tick(const Duration(milliseconds: 80)); tick(const Duration(milliseconds: 80));
expect(reversed.value, closeTo(0.2, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.2));
tick(const Duration(milliseconds: 90)); tick(const Duration(milliseconds: 90));
expect(reversed.value, closeTo(0.1, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.1));
tick(const Duration(milliseconds: 100)); tick(const Duration(milliseconds: 100));
expect(reversed.value, closeTo(0.0, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.0));
controller.reverse(); controller.reverse();
tick(const Duration(milliseconds: 110)); tick(const Duration(milliseconds: 110));
expect(reversed.value, closeTo(0.0, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.0));
tick(const Duration(milliseconds: 120)); tick(const Duration(milliseconds: 120));
expect(reversed.value, closeTo(0.2, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.2));
tick(const Duration(milliseconds: 130)); tick(const Duration(milliseconds: 130));
expect(reversed.value, closeTo(0.4, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.4));
tick(const Duration(milliseconds: 140)); tick(const Duration(milliseconds: 140));
expect(reversed.value, closeTo(0.6, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.6));
tick(const Duration(milliseconds: 150)); tick(const Duration(milliseconds: 150));
expect(reversed.value, closeTo(0.8, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(0.8));
tick(const Duration(milliseconds: 160)); tick(const Duration(milliseconds: 160));
expect(reversed.value, closeTo(1.0, precisionErrorTolerance)); expect(reversed.value, moreOrLessEquals(1.0));
}); });
test('TweenSequence', () { test('TweenSequence', () {
......
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