// 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 it) { Expect.equals(false, it.hasNext()); var exception = null; try { it.next(); } catch (NoMoreElementsException e) { exception = e; } Expect.equals(true, exception != null); } static int sum(int expected, Iterator it) { int count = 0; while (it.hasNext()) { count += it.next(); } Expect.equals(expected, count); } static void testSmallQueue() { Queue queue = new Queue(); queue.addLast(1); queue.addLast(2); queue.addLast(3); Iterator it = queue.iterator(); Expect.equals(true, it.hasNext()); sum(6, it); testThrows(it); } 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(); Expect.equals(true, it.hasNext()); sum(count, it); testThrows(it); } static void testEmptyQueue() { Queue queue = new Queue(); Iterator it = queue.iterator(); Expect.equals(false, it.hasNext()); sum(0, it); testThrows(it); } } main() { QueueIteratorTest.testMain(); }