| Index: tests/corelib/iterable_min_max_test.dart
|
| diff --git a/tests/corelib/iterable_min_max_test.dart b/tests/corelib/iterable_min_max_test.dart
|
| index 1a8c4fd3aeb1e9edace0a9d95145cd0dc7d44e65..d2b23c4015c96569be26d898f0a04f6b8f875d3f 100644
|
| --- a/tests/corelib/iterable_min_max_test.dart
|
| +++ b/tests/corelib/iterable_min_max_test.dart
|
| @@ -13,6 +13,26 @@ class C {
|
| bool operator==(var other) => other is C && x == other.x;
|
| }
|
|
|
| +min(Iterable source, int compare(var a, var b)) {
|
| + Iterator iterator = source.iterator;
|
| + if (!iterator.moveNext()) throw new StateError("no values");
|
| + var min = iterator.current;
|
| + while (iterator.moveNext()) {
|
| + if (compare(min, iterator.current) > 0) min = iterator.current;
|
| + }
|
| + return iterator.current;
|
| +}
|
| +
|
| +max(Iterable source, int compare(var a, var b)) {
|
| + Iterator iterator = source.iterator;
|
| + if (!iterator.moveNext()) throw new StateError("no values");
|
| + var max = iterator.current;
|
| + while (iterator.moveNext()) {
|
| + if (compare(min, iterator.current) < 0) max = iterator.current;
|
| + }
|
| + return iterator.current;
|
| +}
|
| +
|
| const inf = double.INFINITY;
|
|
|
| var intList = const [0, 1, -1, -5, 5, -1000, 1000, -7, 7];
|
| @@ -26,14 +46,14 @@ int compareC(C a, C b) => a.x.compareTo(b.x);
|
| testMinMax(iterable, min, max) {
|
| Expect.equals(min, iterable.min());
|
| Expect.equals(min, iterable.min(Comparable.compare));
|
| - Expect.equals(min, IterableMixinWorkaround.min(iterable));
|
| - Expect.equals(min, IterableMixinWorkaround.min(iterable, Comparable.compare));
|
| + Expect.equals(min, min(iterable));
|
| + Expect.equals(min, min(iterable, Comparable.compare));
|
| Expect.equals(max, iterable.min((a, b) => Comparable.compare(b, a)));
|
|
|
| Expect.equals(max, iterable.max());
|
| Expect.equals(max, iterable.max(Comparable.compare));
|
| - Expect.equals(max, IterableMixinWorkaround.max(iterable));
|
| - Expect.equals(max, IterableMixinWorkaround.max(iterable, Comparable.compare));
|
| + Expect.equals(max, max(iterable));
|
| + Expect.equals(max, max(iterable, Comparable.compare));
|
| Expect.equals(min, iterable.max((a, b) => Comparable.compare(b, a)));
|
| }
|
|
|
| @@ -57,18 +77,18 @@ main() {
|
|
|
| // Objects that are not Comparable.
|
| Expect.equals(const C(0), cList.min(compareC));
|
| - Expect.equals(const C(0), IterableMixinWorkaround.min(cList, compareC));
|
| + Expect.equals(const C(0), min(cList, compareC));
|
| Expect.equals(const C(0), new List.from(cList).min(compareC));
|
| - Expect.equals(const C(0), IterableMixinWorkaround.min(new List.from(cList), compareC));
|
| + Expect.equals(const C(0), min(new List.from(cList), compareC));
|
| Expect.equals(const C(0), new Set.from(cList).min(compareC));
|
| - Expect.equals(const C(0), IterableMixinWorkaround.min(new Set.from(cList), compareC));
|
| + Expect.equals(const C(0), min(new Set.from(cList), compareC));
|
|
|
| Expect.equals(const C(10), cList.max(compareC));
|
| - Expect.equals(const C(10), IterableMixinWorkaround.max(cList, compareC));
|
| + Expect.equals(const C(10), max(cList, compareC));
|
| Expect.equals(const C(10), new List.from(cList).max(compareC));
|
| - Expect.equals(const C(10), IterableMixinWorkaround.max(new List.from(cList), compareC));
|
| + Expect.equals(const C(10), max(new List.from(cList), compareC));
|
| Expect.equals(const C(10), new Set.from(cList).max(compareC));
|
| - Expect.equals(const C(10), IterableMixinWorkaround.max(new Set.from(cList), compareC));
|
| + Expect.equals(const C(10), max(new Set.from(cList), compareC));
|
|
|
| bool checkedMode = false;
|
| assert(checkedMode = true);
|
| @@ -77,4 +97,3 @@ main() {
|
| Expect.throws(cList.max, (e) => checkedMode ? e is TypeError
|
| : e is NoSuchMethodError);
|
| }
|
| -
|
|
|