8bd4bf096b
R=ngeoffray@google.com BUG= Review URL: https://chromiumcodereview.appspot.com//10891020 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11492 260f80e4-7a28-3924-810f-c04153c831b5
68 lines
1.5 KiB
Dart
68 lines
1.5 KiB
Dart
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
class QueueIteratorTest {
|
|
static testMain() {
|
|
testSmallQueue();
|
|
testLargeQueue();
|
|
testEmptyQueue();
|
|
}
|
|
|
|
static void testThrows(Iterator<int> it) {
|
|
Expect.equals(false, it.hasNext());
|
|
var exception = null;
|
|
try {
|
|
it.next();
|
|
} on NoMoreElementsException catch (e) {
|
|
exception = e;
|
|
}
|
|
Expect.equals(true, exception != null);
|
|
}
|
|
|
|
static int sum(int expected, Iterator<int> it) {
|
|
int count = 0;
|
|
while (it.hasNext()) {
|
|
count += it.next();
|
|
}
|
|
Expect.equals(expected, count);
|
|
}
|
|
|
|
static void testSmallQueue() {
|
|
Queue<int> queue = new Queue<int>();
|
|
queue.addLast(1);
|
|
queue.addLast(2);
|
|
queue.addLast(3);
|
|
|
|
Iterator<int> it = queue.iterator();
|
|
Expect.equals(true, it.hasNext());
|
|
sum(6, it);
|
|
testThrows(it);
|
|
}
|
|
|
|
static void testLargeQueue() {
|
|
Queue<int> queue = new Queue<int>();
|
|
int count = 0;
|
|
for (int i = 0; i < 100; i++) {
|
|
count += i;
|
|
queue.addLast(i);
|
|
}
|
|
Iterator<int> it = queue.iterator();
|
|
Expect.equals(true, it.hasNext());
|
|
sum(count, it);
|
|
testThrows(it);
|
|
}
|
|
|
|
static void testEmptyQueue() {
|
|
Queue<int> queue = new Queue<int>();
|
|
Iterator<int> it = queue.iterator();
|
|
Expect.equals(false, it.hasNext());
|
|
sum(0, it);
|
|
testThrows(it);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
QueueIteratorTest.testMain();
|
|
}
|