mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 08:51:21 +00:00
62f84880ef
Closes #40520 Closes #40948 Closes #40425 Change-Id: I0aa3cfa51b410c90dd0bea963846eeb6b2e73efb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140540 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
59 lines
1.3 KiB
Dart
59 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 void 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();
|
|
}
|