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

Side by Side Diff: tests/corelib/queue_iterator_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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/corelib/queue_first_test.dart ('k') | tests/corelib/queue_last_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 QueueIteratorTest { 5 class QueueIteratorTest {
6 static testMain() { 6 static testMain() {
7 testSmallQueue(); 7 testSmallQueue();
8 testLargeQueue(); 8 testLargeQueue();
9 testEmptyQueue(); 9 testEmptyQueue();
10 } 10 }
11 11
12 static void testThrows(Iterator<int> it) {
13 Expect.equals(false, it.hasNext);
14 var exception = null;
15 try {
16 it.next();
17 } on StateError catch (e) {
18 exception = e;
19 }
20 Expect.equals(true, exception != null);
21 }
22
23 static int sum(int expected, Iterator<int> it) { 12 static int sum(int expected, Iterator<int> it) {
24 int count = 0; 13 int count = 0;
25 while (it.hasNext) { 14 while (it.moveNext()) {
26 count += it.next(); 15 count += it.current;
27 } 16 }
28 Expect.equals(expected, count); 17 Expect.equals(expected, count);
29 } 18 }
30 19
31 static void testSmallQueue() { 20 static void testSmallQueue() {
32 Queue<int> queue = new Queue<int>(); 21 Queue<int> queue = new Queue<int>();
33 queue.addLast(1); 22 queue.addLast(1);
34 queue.addLast(2); 23 queue.addLast(2);
35 queue.addLast(3); 24 queue.addLast(3);
36 25
37 Iterator<int> it = queue.iterator(); 26 Iterator<int> it = queue.iterator;
38 Expect.equals(true, it.hasNext);
39 sum(6, it); 27 sum(6, it);
40 testThrows(it); 28 Expect.isFalse(it.moveNext());
29 Expect.isNull(it.current);
41 } 30 }
42 31
43 static void testLargeQueue() { 32 static void testLargeQueue() {
44 Queue<int> queue = new Queue<int>(); 33 Queue<int> queue = new Queue<int>();
45 int count = 0; 34 int count = 0;
46 for (int i = 0; i < 100; i++) { 35 for (int i = 0; i < 100; i++) {
47 count += i; 36 count += i;
48 queue.addLast(i); 37 queue.addLast(i);
49 } 38 }
50 Iterator<int> it = queue.iterator(); 39 Iterator<int> it = queue.iterator;
51 Expect.equals(true, it.hasNext);
52 sum(count, it); 40 sum(count, it);
53 testThrows(it); 41 Expect.isFalse(it.moveNext());
42 Expect.isNull(it.current);
54 } 43 }
55 44
56 static void testEmptyQueue() { 45 static void testEmptyQueue() {
57 Queue<int> queue = new Queue<int>(); 46 Queue<int> queue = new Queue<int>();
58 Iterator<int> it = queue.iterator(); 47 Iterator<int> it = queue.iterator;
59 Expect.equals(false, it.hasNext);
60 sum(0, it); 48 sum(0, it);
61 testThrows(it); 49 Expect.isFalse(it.moveNext());
50 Expect.isNull(it.current);
62 } 51 }
63 } 52 }
64 53
65 main() { 54 main() {
66 QueueIteratorTest.testMain(); 55 QueueIteratorTest.testMain();
67 } 56 }
OLDNEW
« no previous file with comments | « tests/corelib/queue_first_test.dart ('k') | tests/corelib/queue_last_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698