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

Unified Diff: tests/corelib/list_reversed_test.dart

Issue 11896013: Add List.reversed to give a reverse fixed-length view of a list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Moved some functionality to separate CL. 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/list_iterators_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/list_reversed_test.dart
diff --git a/tests/corelib/list_reversed_test.dart b/tests/corelib/list_reversed_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..03b99ce4432d72224a96914557b47b79bdde41c0
--- /dev/null
+++ b/tests/corelib/list_reversed_test.dart
@@ -0,0 +1,40 @@
+// 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.
+
+
+main() {
+ testOperations();
+}
+
+void testOperations() {
+ // Comparison lists.
+ List l = const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+ List r = const [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
+ // A base list that starts out like l.
+ List base = l.toList();
+ // A lazy reverse of base.
+ List reversed = base.reversed;
+
+ Expect.listEquals(r, reversed);
+ Expect.listEquals(l, reversed.reversed);
+ for (int i = 0; i < r.length; i++) {
+ Expect.equals(r[i], reversed[i]);
+ }
+ Expect.equals(4, base.indexOf(5));
+ Expect.equals(5, reversed.indexOf(5));
+
+ // Combinations of start and end relative to start/end of list.
+ List subr = [8, 7, 6, 5, 4, 3];
+ Expect.listEquals(subr, reversed.skip(2).take(6));
+ Expect.listEquals(subr, reversed.take(8).skip(2));
+ Expect.listEquals(subr, reversed.reversed.skip(2).take(6).reversed);
+ Expect.listEquals(subr, reversed.reversed.take(8).skip(2).reversed);
+ Expect.listEquals(subr, reversed.take(8).reversed.take(6).reversed);
+ Expect.listEquals(subr, reversed.reversed.take(8).reversed.take(6));
+ Expect.listEquals(subr, reversed.reversed.skip(2).reversed.skip(2));
+ Expect.listEquals(subr, reversed.skip(2).reversed.skip(2).reversed);
+
+ // Reverse const list.
+ Expect.listEquals(r, l.reversed);
+}
« no previous file with comments | « tests/corelib/list_iterators_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698