Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: pkg/unittest/lib/src/iterable_matchers.dart

Issue 116273006: Implement _UnorderedEquals in terms of _UnorderedMatches in pkg/unittest. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/iterable_matchers.dart
diff --git a/pkg/unittest/lib/src/iterable_matchers.dart b/pkg/unittest/lib/src/iterable_matchers.dart
index a81bfed347b341512ff204baae05ff080be9e826..2189286825f9e55702c977595f22eadbdc010ca6 100644
--- a/pkg/unittest/lib/src/iterable_matchers.dart
+++ b/pkg/unittest/lib/src/iterable_matchers.dart
@@ -115,63 +115,20 @@ class _OrderedEquals extends Matcher {
* the same order. Note that this is O(n^2) so should only be used on
* small objects.
*/
-Matcher unorderedEquals(Iterable expected) =>
- new _UnorderedEquals(expected);
+Matcher unorderedEquals(Iterable expected) => new _UnorderedEquals(expected);
-class _UnorderedEquals extends Matcher {
- Iterable _expected;
+class _UnorderedEquals extends _UnorderedMatches {
+ final List _expectedValues;
- _UnorderedEquals(Iterable this._expected);
-
- String _test(item) {
- if (item is !Iterable) {
- return 'not iterable';
- }
- // Check the lengths are the same.
- var expectedLength = _expected.length;
- var actualLength = item.length;
- if (expectedLength > actualLength) {
- return 'has too few elements (${actualLength} < ${expectedLength})';
- } else if (expectedLength < actualLength) {
- return 'has too many elements (${actualLength} > ${expectedLength})';
- }
- List<bool> matched = new List<bool>(actualLength);
- for (var i = 0; i < actualLength; i++) {
- matched[i] = false;
- }
- var expectedPosition = 0;
- for (var expectedElement in _expected) {
- var actualPosition = 0;
- var gotMatch = false;
- for (var actualElement in item) {
- if (!matched[actualPosition]) {
- if (expectedElement == actualElement) {
- matched[actualPosition] = gotMatch = true;
- break;
- }
- }
- ++actualPosition;
- }
- if (!gotMatch) {
- Description reason = new StringDescription();
- reason.add('has no match for element ').
- addDescriptionOf(expectedElement).
- add(' at index ${expectedPosition}');
- return reason.toString();
- }
- ++expectedPosition;
- }
- return null;
- }
-
- bool matches(item, Map mismatchState) => (_test(item) == null);
+ _UnorderedEquals(Iterable expected)
+ : super(expected.map(equals)),
+ _expectedValues = expected.toList();
Description describe(Description description) =>
- description.add('equals ').addDescriptionOf(_expected).add(' unordered');
-
- Description describeMismatch(item, Description mismatchDescription,
- Map matchState, bool verbose) =>
- mismatchDescription.add(_test(item));
+ description
+ .add('equals ')
+ .addDescriptionOf(_expectedValues)
+ .add(' unordered');
}
/**
« no previous file with comments | « no previous file | pkg/unittest/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698