mirror of
https://github.com/flutter/flutter
synced 2024-09-19 08:11:56 +00:00
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.
This commit is contained in:
parent
11d1d54c8a
commit
79c8e5c7c7
|
@ -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';
|
||||
}
|
||||
|
|
13
packages/flutter/test/physics/gravity_simulation_test.dart
Normal file
13
packages/flutter/test/physics/gravity_simulation_test.dart
Normal file
|
@ -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));
|
||||
});
|
||||
}
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue