02a8b015ad
Change-Id: I1783f624c7ce7d3b962c301c27ac0f4422d7c28f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126824 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
62 lines
1.4 KiB
Dart
62 lines
1.4 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.
|
|
|
|
library queue.iterator.test;
|
|
|
|
import "package:expect/expect.dart";
|
|
import 'dart:collection' show Queue;
|
|
|
|
class QueueIteratorTest {
|
|
static testMain() {
|
|
testSmallQueue();
|
|
testLargeQueue();
|
|
testEmptyQueue();
|
|
}
|
|
|
|
static int sum(int expected, Iterator<int> it) {
|
|
int count = 0;
|
|
while (it.moveNext()) {
|
|
count += it.current;
|
|
}
|
|
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;
|
|
sum(6, it);
|
|
Expect.isFalse(it.moveNext());
|
|
Expect.isNull(it.current);
|
|
}
|
|
|
|
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;
|
|
sum(count, it);
|
|
Expect.isFalse(it.moveNext());
|
|
Expect.isNull(it.current);
|
|
}
|
|
|
|
static void testEmptyQueue() {
|
|
Queue<int> queue = new Queue<int>();
|
|
Iterator<int> it = queue.iterator;
|
|
sum(0, it);
|
|
Expect.isFalse(it.moveNext());
|
|
Expect.isNull(it.current);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
QueueIteratorTest.testMain();
|
|
}
|