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

Side by Side Diff: tests/corelib/src/QueueIteratorTest.dart

Issue 10244009: test rename overhaul: step 7 - corelib tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class QueueIteratorTest {
6 static testMain() {
7 testSmallQueue();
8 testLargeQueue();
9 testEmptyQueue();
10 }
11
12 static void testThrows(Iterator<int> it) {
13 Expect.equals(false, it.hasNext());
14 var exception = null;
15 try {
16 it.next();
17 } catch (NoMoreElementsException e) {
18 exception = e;
19 }
20 Expect.equals(true, exception != null);
21 }
22
23 static int sum(int expected, Iterator<int> it) {
24 int count = 0;
25 while (it.hasNext()) {
26 count += it.next();
27 }
28 Expect.equals(expected, count);
29 }
30
31 static void testSmallQueue() {
32 Queue<int> queue = new Queue<int>();
33 queue.addLast(1);
34 queue.addLast(2);
35 queue.addLast(3);
36
37 Iterator<int> it = queue.iterator();
38 Expect.equals(true, it.hasNext());
39 sum(6, it);
40 testThrows(it);
41 }
42
43 static void testLargeQueue() {
44 Queue<int> queue = new Queue<int>();
45 int count = 0;
46 for (int i = 0; i < 100; i++) {
47 count += i;
48 queue.addLast(i);
49 }
50 Iterator<int> it = queue.iterator();
51 Expect.equals(true, it.hasNext());
52 sum(count, it);
53 testThrows(it);
54 }
55
56 static void testEmptyQueue() {
57 Queue<int> queue = new Queue<int>();
58 Iterator<int> it = queue.iterator();
59 Expect.equals(false, it.hasNext());
60 sum(0, it);
61 testThrows(it);
62 }
63 }
64
65 main() {
66 QueueIteratorTest.testMain();
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698