// 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 it) { int count = 0; while (it.moveNext()) { count += it.current; } Expect.equals(expected, count); } static void testSmallQueue() { Queue queue = new Queue(); queue.addLast(1); queue.addLast(2); queue.addLast(3); Iterator it = queue.iterator; sum(6, it); Expect.isFalse(it.moveNext()); } static void testLargeQueue() { Queue queue = new Queue(); int count = 0; for (int i = 0; i < 100; i++) { count += i; queue.addLast(i); } Iterator it = queue.iterator; sum(count, it); Expect.isFalse(it.moveNext()); } static void testEmptyQueue() { Queue queue = new Queue(); Iterator it = queue.iterator; sum(0, it); Expect.isFalse(it.moveNext()); } } main() { QueueIteratorTest.testMain(); }