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

Side by Side Diff: tests/corelib/list_iterators_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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class ListIteratorsTest { 5 class ListIteratorsTest {
6 static void checkListIterator(List a) { 6 static void checkListIterator(List a) {
7 Iterator it = a.iterator; 7 Iterator it = a.iterator;
8 Expect.isNull(it.current);
8 for (int i = 0; i < a.length; i++) { 9 for (int i = 0; i < a.length; i++) {
9 Expect.isTrue(it.moveNext()); 10 Expect.isTrue(it.moveNext());
10 var elem = it.current; 11 var elem = it.current;
11 Expect.equals(a[i], elem); 12 Expect.equals(a[i], elem);
12 } 13 }
13 Expect.isFalse(it.moveNext()); 14 Expect.isFalse(it.moveNext());
14 Expect.isNull(it.current); 15 Expect.isNull(it.current);
15 } 16 }
16 17
17 static testMain() { 18 static testMain() {
18 checkListIterator([]); 19 checkListIterator([]);
19 checkListIterator([1, 2]); 20 checkListIterator([1, 2]);
20 checkListIterator(new List.fixedLength(0)); 21 checkListIterator(new List.fixedLength(0));
21 checkListIterator(new List.fixedLength(10)); 22 checkListIterator(new List.fixedLength(10));
22 checkListIterator(new List()); 23 checkListIterator(new List());
23 List g = new List(); 24 List g = new List();
24 g.addAll([1, 2, 3]); 25 g.addAll([1, 2, 3]);
25 checkListIterator(g); 26 checkListIterator(g);
26 27
27 // This is mostly undefined behavior. 28 // This is mostly undefined behavior.
28 Iterator it = g.iterator; 29 Iterator it = g.iterator;
29 Expect.isTrue(it.moveNext()); 30 Expect.isTrue(it.moveNext());
30 g.removeLast();
31 Expect.equals(1, it.current); 31 Expect.equals(1, it.current);
32 Expect.isTrue(it.moveNext()); 32 Expect.isTrue(it.moveNext());
33 g[1] = 49; 33 g[1] = 49;
34 // The iterator keeps the last value. 34 // The iterator keeps the last value.
35 Expect.equals(2, it.current); 35 Expect.equals(2, it.current);
36 Expect.isTrue(it.moveNext());
36 g.removeLast(); 37 g.removeLast();
37 // The iterator keeps the last value. 38 // The iterator keeps the last value.
38 Expect.equals(2, it.current); 39 Expect.equals(3, it.current);
39 Expect.isFalse(it.moveNext());
40 Expect.isNull(it.current);
41
42 g.clear();
43 g.addAll([10, 20]);
44 int sum = 0;
45 for (var elem in g) {
46 sum += elem;
47 // Iterator must realize that g has no more elements.
48 g.removeLast();
49 }
50 Expect.equals(10, sum);
51 } 40 }
52 } 41 }
53 42
54 main() { 43 main() {
55 ListIteratorsTest.testMain(); 44 ListIteratorsTest.testMain();
56 } 45 }
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | tests/corelib/list_reversed_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698