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

Unified Diff: tests/corelib/iterable_min_max_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months 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 | « tests/corelib/iterable_length_test.dart ('k') | tests/corelib/iterable_single_matching_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0a64a01a7a1c866c6028d197500d32caa758598a
--- /dev/null
+++ b/tests/corelib/iterable_min_max_test.dart
@@ -0,0 +1,78 @@
+// 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;
+}
+
+const 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.compareTo(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(new Set(), 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));
+
+ bool checkedMode = false;
+ assert(checkedMode = true);
+ Expect.throws(cList.min, (e) => checkedMode ? e is TypeError
+ : e is NoSuchMethodError);
+ Expect.throws(cList.max, (e) => checkedMode ? e is TypeError
+ : e is NoSuchMethodError);
+}
+
« no previous file with comments | « tests/corelib/iterable_length_test.dart ('k') | tests/corelib/iterable_single_matching_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698