| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..71c7fda2efe56d4a529da63c19c2b553ac31d1a2
|
| --- /dev/null
|
| +++ b/tests/corelib/iterable_min_max_test.dart
|
| @@ -0,0 +1,73 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +#import "dart:collection";
|
| +
|
| +class C {
|
| + final x;
|
| + const C(this.x);
|
| + int get hashCode => x.hashCode;
|
| + bool operator==(var other) => other is C && x == other.x;
|
| +}
|
| +
|
| +var inf = Double.INFINITY;
|
| +
|
| +var intList = const [0,1,-1,-5,5,-1000,1000,-7,7];
|
| +var doubleList = const [-0.0, 0.0, -1.0, 1.0, -1000.0, 1000.0, -inf, inf];
|
| +var stringList = const ["bbb", "bba", "bab", "abb", "bbc", "bcb", "cbb", "bb"];
|
| +var cList = const [const C(5), const C(3), const C(8),
|
| + const C(0), const C(10), const C(6)];
|
| +int compareC(C a, C b) => a.x.compare(b.x);
|
| +
|
| +
|
| +testMinMax(iterable, min, max) {
|
| + Expect.equals(min, iterable.min());
|
| + Expect.equals(min, iterable.min(Comparable.compare));
|
| + Expect.equals(min, Collections.min(iterable));
|
| + Expect.equals(min, Collections.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, Collections.max(iterable));
|
| + Expect.equals(max, Collections.max(iterable, Comparable.compare));
|
| + Expect.equals(min, iterable.max((a, b) => Comparable.compare(b, a)));
|
| +}
|
| +
|
| +
|
| +main() {
|
| + testMinMax(const [], null, null);
|
| + testMinMax([], null, null);
|
| +
|
| + testMinMax(intList, -1000, 1000); // Const list.
|
| + testMinMax(new List.from(intList), -1000, 1000); // Non-const list.
|
| + testMinMax(new Set.from(intList), -1000, 1000); // Set.
|
| +
|
| + testMinMax(doubleList, -inf, inf);
|
| + testMinMax(new List.from(doubleList), -inf, inf);
|
| + testMinMax(new Set.from(doubleList), -inf, inf);
|
| +
|
| + testMinMax(stringList, "abb", "cbb");
|
| + testMinMax(new List.from(stringList), "abb", "cbb");
|
| + testMinMax(new Set.from(stringList), "abb", "cbb");
|
| +
|
| + // Objects that are not Comparable.
|
| + Expect.equals(const C(0), cList.min(compareC));
|
| + Expect.equals(const C(0), Collections.min(cList, compareC));
|
| + Expect.equals(const C(0), new List.from(cList).min(compareC));
|
| + Expect.equals(const C(0), Collections.min(new List.from(cList), compareC));
|
| + Expect.equals(const C(0), new Set.from(cList).min(compareC));
|
| + Expect.equals(const C(0), Collections.min(new Set.from(cList), compareC));
|
| +
|
| + Expect.equals(const C(10), cList.max(compareC));
|
| + Expect.equals(const C(10), Collections.max(cList, compareC));
|
| + Expect.equals(const C(10), new List.from(cList).max(compareC));
|
| + Expect.equals(const C(10), Collections.max(new List.from(cList), compareC));
|
| + Expect.equals(const C(10), new Set.from(cList).max(compareC));
|
| + Expect.equals(const C(10), Collections.max(new Set.from(cList), compareC));
|
| +
|
| + Expect.throws(cList.min, (e) => e is NoSuchMethodError);
|
| + Expect.throws(cList.max, (e) => e is NoSuchMethodError);
|
| +}
|
| +
|
|
|