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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/corelib/list_iterators_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5
6 main() {
7 testOperations();
8 }
9
10 void testOperations() {
11 // Comparison lists.
12 List l = const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
13 List r = const [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
14 // A base list that starts out like l.
15 List base = l.toList();
16 // A lazy reverse of base.
17 List reversed = base.reversed;
18
19 Expect.listEquals(r, reversed);
20 Expect.listEquals(l, reversed.reversed);
21 for (int i = 0; i < r.length; i++) {
22 Expect.equals(r[i], reversed[i]);
23 }
24 Expect.equals(4, base.indexOf(5));
25 Expect.equals(5, reversed.indexOf(5));
26
27 // Combinations of start and end relative to start/end of list.
28 List subr = [8, 7, 6, 5, 4, 3];
29 Expect.listEquals(subr, reversed.skip(2).take(6));
30 Expect.listEquals(subr, reversed.take(8).skip(2));
31 Expect.listEquals(subr, reversed.reversed.skip(2).take(6).reversed);
32 Expect.listEquals(subr, reversed.reversed.take(8).skip(2).reversed);
33 Expect.listEquals(subr, reversed.take(8).reversed.take(6).reversed);
34 Expect.listEquals(subr, reversed.reversed.take(8).reversed.take(6));
35 Expect.listEquals(subr, reversed.reversed.skip(2).reversed.skip(2));
36 Expect.listEquals(subr, reversed.skip(2).reversed.skip(2).reversed);
37
38 // Reverse const list.
39 Expect.listEquals(r, l.reversed);
40 }
OLDNEW
« 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