OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library queue.test; | 5 library queue.test; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 abstract class QueueTest { | 10 abstract class QueueTest { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 Queue queue = newQueue(); | 253 Queue queue = newQueue(); |
254 Expect.isTrue(queue.isEmpty); | 254 Expect.isTrue(queue.isEmpty); |
255 | 255 |
256 for (int i = 0; i < N; i++) { | 256 for (int i = 0; i < N; i++) { |
257 queue.add(i); | 257 queue.add(i); |
258 set.add(i); | 258 set.add(i); |
259 } | 259 } |
260 Expect.equals(N, queue.length); | 260 Expect.equals(N, queue.length); |
261 Expect.isFalse(queue.isEmpty); | 261 Expect.isFalse(queue.isEmpty); |
262 | 262 |
| 263 Expect.equals(0, queue.elementAt(0)); |
| 264 Expect.equals(N - 1, queue.elementAt(N - 1)); |
| 265 Expect.throws(() { queue.elementAt(-1); }); |
| 266 Expect.throws(() { queue.elementAt(N); }); |
| 267 |
263 Iterable skip1 = queue.skip(1); | 268 Iterable skip1 = queue.skip(1); |
264 Iterable take1 = queue.take(1); | 269 Iterable take1 = queue.take(1); |
265 Iterable mapped = queue.map((e) => -e); | 270 Iterable mapped = queue.map((e) => -e); |
266 | 271 |
267 for (int i = 0; i < 500; i++) { | 272 for (int i = 0; i < 500; i++) { |
268 Expect.equals(i, take1.first); | 273 Expect.equals(i, take1.first); |
269 Expect.equals(i, queue.first); | 274 Expect.equals(i, queue.first); |
270 Expect.equals(-i, mapped.first); | 275 Expect.equals(-i, mapped.first); |
271 Expect.equals(i + 1, skip1.first); | 276 Expect.equals(i + 1, skip1.first); |
272 Expect.equals(i, queue.removeFirst()); | 277 Expect.equals(i, queue.removeFirst()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 413 } |
409 Expect.equals(null, entry2); | 414 Expect.equals(null, entry2); |
410 } | 415 } |
411 } | 416 } |
412 | 417 |
413 | 418 |
414 main() { | 419 main() { |
415 new DoubleLinkedQueueTest().testMain(); | 420 new DoubleLinkedQueueTest().testMain(); |
416 new ListQueueTest().testMain(); | 421 new ListQueueTest().testMain(); |
417 } | 422 } |
OLD | NEW |