From 79c8e5c7c7daaacb1798085ee7a856d512ec4f4f Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 5 Jan 2017 16:33:40 -0800 Subject: [PATCH] Add a toString to Simulation (#7364) Also, make hasOneLineDescription more discerning. Also, add a test for hasOneLineDescription. Also, add a test for GravitySimulation, to test the toString. --- packages/flutter/lib/src/physics/simulation.dart | 3 +++ .../test/physics/gravity_simulation_test.dart | 13 +++++++++++++ packages/flutter/test/physics/near_equal_test.dart | 2 +- packages/flutter/test/physics/newton_test.dart | 2 +- packages/flutter_test/lib/src/matchers.dart | 5 +++-- packages/flutter_test/test/matchers_test.dart | 8 ++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 packages/flutter/test/physics/gravity_simulation_test.dart diff --git a/packages/flutter/lib/src/physics/simulation.dart b/packages/flutter/lib/src/physics/simulation.dart index 13357bace2..5c144a6a51 100644 --- a/packages/flutter/lib/src/physics/simulation.dart +++ b/packages/flutter/lib/src/physics/simulation.dart @@ -47,4 +47,7 @@ abstract class Simulation { /// asymptote itself could not be seen, it would be pointless to continue. The /// tolerance defines how to determine if the difference could not be seen. Tolerance tolerance = Tolerance.defaultTolerance; + + @override + String toString() => '$runtimeType'; } diff --git a/packages/flutter/test/physics/gravity_simulation_test.dart b/packages/flutter/test/physics/gravity_simulation_test.dart new file mode 100644 index 0000000000..0e4f2c0e05 --- /dev/null +++ b/packages/flutter/test/physics/gravity_simulation_test.dart @@ -0,0 +1,13 @@ +// Copyright 2017 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/physics.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('gravity simulation', () { + expect(new GravitySimulation(9.81, 10.0, 0.0, 0.0), hasOneLineDescription); + expect(new GravitySimulation(9.81, 10.0, 0.0, 0.0).x(10.0), moreOrLessEquals(50.0 * 9.81 + 10.0)); + }); +} diff --git a/packages/flutter/test/physics/near_equal_test.dart b/packages/flutter/test/physics/near_equal_test.dart index 4dd45f2b75..4dce1c48a0 100644 --- a/packages/flutter/test/physics/near_equal_test.dart +++ b/packages/flutter/test/physics/near_equal_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 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. diff --git a/packages/flutter/test/physics/newton_test.dart b/packages/flutter/test/physics/newton_test.dart index b99220cea5..bb9af367b7 100644 --- a/packages/flutter/test/physics/newton_test.dart +++ b/packages/flutter/test/physics/newton_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 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. diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index 3433965e3e..17844c8bcd 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -62,8 +62,8 @@ const Matcher isNotInCard = const _IsNotInCard(); /// Asserts that an object's toString() is a plausible one-line description. /// /// Specifically, this matcher checks that the string does not contains newline -/// characters, and does not have leading or trailing whitespace, and is not -/// empty. +/// characters, and does not have leading or trailing whitespace, is not +/// empty, and does not contain the default `Instance of ...` string. const Matcher hasOneLineDescription = const _HasOneLineDescription(); /// Asserts that two [double]s are equal, within some tolerated error. @@ -242,6 +242,7 @@ class _HasOneLineDescription extends Matcher { String description = object.toString(); return description.isNotEmpty && !description.contains('\n') + && !description.contains('Instance of ') && description.trim() == description; } diff --git a/packages/flutter_test/test/matchers_test.dart b/packages/flutter_test/test/matchers_test.dart index c4cf2be70d..64ed12747c 100644 --- a/packages/flutter_test/test/matchers_test.dart +++ b/packages/flutter_test/test/matchers_test.dart @@ -5,6 +5,14 @@ import 'package:flutter_test/flutter_test.dart'; void main() { + test('hasOneLineDescription', () { + expect('Hello', hasOneLineDescription); + expect('Hello\nHello', isNot(hasOneLineDescription)); + expect(' Hello', isNot(hasOneLineDescription)); + expect('Hello ', isNot(hasOneLineDescription)); + expect(new Object(), isNot(hasOneLineDescription)); + }); + test('moreOrLessEquals', () { expect(0.0, moreOrLessEquals(1e-11)); expect(1e-11, moreOrLessEquals(0.0));