| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library matcher.numeric_matchers; | 5 library matcher.numeric_matchers; |
| 6 | 6 |
| 7 import 'interfaces.dart'; | 7 import 'interfaces.dart'; |
| 8 | 8 |
| 9 /// Returns a matcher which matches if the match argument is greater | 9 /// Returns a matcher which matches if the match argument is greater |
| 10 /// than the given [value]. | 10 /// than the given [value]. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 Description describeMismatch(item, Description mismatchDescription, | 106 Description describeMismatch(item, Description mismatchDescription, |
| 107 Map matchState, bool verbose) { | 107 Map matchState, bool verbose) { |
| 108 mismatchDescription.add('is not '); | 108 mismatchDescription.add('is not '); |
| 109 return describe(mismatchDescription); | 109 return describe(mismatchDescription); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 /// Returns a matcher which matches if the match argument is within [delta] | 113 /// Returns a matcher which matches if the match argument is within [delta] |
| 114 /// of some [value]; i.e. if the match argument is greater than | 114 /// of some [value]. |
| 115 /// |
| 116 /// In other words, this matches if the match argument is greater than |
| 115 /// than or equal [value]-[delta] and less than or equal to [value]+[delta]. | 117 /// than or equal [value]-[delta] and less than or equal to [value]+[delta]. |
| 116 Matcher closeTo(num value, num delta) => new _IsCloseTo(value, delta); | 118 Matcher closeTo(num value, num delta) => new _IsCloseTo(value, delta); |
| 117 | 119 |
| 118 class _IsCloseTo extends Matcher { | 120 class _IsCloseTo extends Matcher { |
| 119 final num _value, _delta; | 121 final num _value, _delta; |
| 120 | 122 |
| 121 const _IsCloseTo(this._value, this._delta); | 123 const _IsCloseTo(this._value, this._delta); |
| 122 | 124 |
| 123 bool matches(item, Map matchState) { | 125 bool matches(item, Map matchState) { |
| 124 if (!_isNumeric(item)) { | 126 if (!_isNumeric(item)) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (item is !num) { | 204 if (item is !num) { |
| 203 return mismatchDescription. | 205 return mismatchDescription. |
| 204 addDescriptionOf(item). | 206 addDescriptionOf(item). |
| 205 add(' not numeric'); | 207 add(' not numeric'); |
| 206 } else { | 208 } else { |
| 207 return super.describeMismatch(item, mismatchDescription, | 209 return super.describeMismatch(item, mismatchDescription, |
| 208 matchState, verbose); | 210 matchState, verbose); |
| 209 } | 211 } |
| 210 } | 212 } |
| 211 } | 213 } |
| OLD | NEW |