OLD | NEW |
| (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 library queue.iterator.test; | |
6 | |
7 import "package:expect/expect.dart"; | |
8 import 'dart:collection' show Queue; | |
9 | |
10 class QueueIteratorTest { | |
11 static testMain() { | |
12 testSmallQueue(); | |
13 testLargeQueue(); | |
14 testEmptyQueue(); | |
15 } | |
16 | |
17 static int sum(int expected, Iterator<int> it) { | |
18 int count = 0; | |
19 while (it.moveNext()) { | |
20 count += it.current; | |
21 } | |
22 Expect.equals(expected, count); | |
23 } | |
24 | |
25 static void testSmallQueue() { | |
26 Queue<int> queue = new Queue<int>(); | |
27 queue.addLast(1); | |
28 queue.addLast(2); | |
29 queue.addLast(3); | |
30 | |
31 Iterator<int> it = queue.iterator; | |
32 sum(6, it); | |
33 Expect.isFalse(it.moveNext()); | |
34 Expect.isNull(it.current); | |
35 } | |
36 | |
37 static void testLargeQueue() { | |
38 Queue<int> queue = new Queue<int>(); | |
39 int count = 0; | |
40 for (int i = 0; i < 100; i++) { | |
41 count += i; | |
42 queue.addLast(i); | |
43 } | |
44 Iterator<int> it = queue.iterator; | |
45 sum(count, it); | |
46 Expect.isFalse(it.moveNext()); | |
47 Expect.isNull(it.current); | |
48 } | |
49 | |
50 static void testEmptyQueue() { | |
51 Queue<int> queue = new Queue<int>(); | |
52 Iterator<int> it = queue.iterator; | |
53 sum(0, it); | |
54 Expect.isFalse(it.moveNext()); | |
55 Expect.isNull(it.current); | |
56 } | |
57 } | |
58 | |
59 main() { | |
60 QueueIteratorTest.testMain(); | |
61 } | |
OLD | NEW |