mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:10:22 +00:00
e7a524e8c4
Change-Id: Ib235c213861f819ed11a887283cad085582eaac7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132941 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Mark Zhou <markzipan@google.com>
58 lines
1.3 KiB
Dart
58 lines
1.3 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());
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
static void testEmptyQueue() {
|
|
Queue<int> queue = new Queue<int>();
|
|
Iterator<int> it = queue.iterator;
|
|
sum(0, it);
|
|
Expect.isFalse(it.moveNext());
|
|
}
|
|
}
|
|
|
|
main() {
|
|
QueueIteratorTest.testMain();
|
|
}
|