| 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 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 abstract class QueueTest { | 9 abstract class QueueTest { |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 queue.add(0); | 111 queue.add(0); |
| 112 for (int i = 0; i < 255; i++) { | 112 for (int i = 0; i < 255; i++) { |
| 113 queue.add(i + 1); | 113 queue.add(i + 1); |
| 114 Expect.equals(i, queue.removeFirst()); | 114 Expect.equals(i, queue.removeFirst()); |
| 115 } | 115 } |
| 116 Expect.equals(255, queue.removeFirst()); | 116 Expect.equals(255, queue.removeFirst()); |
| 117 Expect.isTrue(queue.isEmpty); | 117 Expect.isTrue(queue.isEmpty); |
| 118 | 118 |
| 119 testAddAll(); | 119 testAddAll(); |
| 120 testLarge(); | 120 testLarge(); |
| 121 testFromListToList(); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void checkQueue(Queue queue, int expectedSize, int expectedSum) { | 124 void checkQueue(Queue queue, int expectedSize, int expectedSum) { |
| 124 Expect.equals(expectedSize, queue.length); | 125 Expect.equals(expectedSize, queue.length); |
| 125 int sum = 0; | 126 int sum = 0; |
| 126 void sumElements(int value) { | 127 void sumElements(int value) { |
| 127 sum += value; | 128 sum += value; |
| 128 } | 129 } |
| 129 queue.forEach(sumElements); | 130 queue.forEach(sumElements); |
| 130 Expect.equals(expectedSum, sum); | 131 Expect.equals(expectedSum, sum); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 queue.forEach((element) { Expect.isTrue(set.contains(element)); }); | 232 queue.forEach((element) { Expect.isTrue(set.contains(element)); }); |
| 232 | 233 |
| 233 queue.addAll(set); | 234 queue.addAll(set); |
| 234 Expect.equals(N * 2, queue.length); | 235 Expect.equals(N * 2, queue.length); |
| 235 Expect.isFalse(queue.isEmpty); | 236 Expect.isFalse(queue.isEmpty); |
| 236 | 237 |
| 237 queue.clear(); | 238 queue.clear(); |
| 238 Expect.equals(0, queue.length); | 239 Expect.equals(0, queue.length); |
| 239 Expect.isTrue(queue.isEmpty); | 240 Expect.isTrue(queue.isEmpty); |
| 240 } | 241 } |
| 242 |
| 243 void testFromListToList() { |
| 244 const int N = 256; |
| 245 List list = []; |
| 246 for (int i = 0; i < N; i++) { |
| 247 Queue queue = newQueueFrom(list); |
| 248 |
| 249 Expect.equals(list.length, queue.length); |
| 250 List to = queue.toList(); |
| 251 Expect.listEquals(list, to); |
| 252 |
| 253 queue.add(i); |
| 254 list.add(i); |
| 255 Expect.equals(list.length, queue.length); |
| 256 to = queue.toList(); |
| 257 Expect.listEquals(list, to); |
| 258 } |
| 259 } |
| 241 } | 260 } |
| 242 | 261 |
| 243 class ListQueueTest extends QueueTest { | 262 class ListQueueTest extends QueueTest { |
| 244 Queue newQueue() => new ListQueue(); | 263 Queue newQueue() => new ListQueue(); |
| 245 Queue newQueueFrom(Iterable elements) => new ListQueue.from(elements); | 264 Queue newQueueFrom(Iterable elements) => new ListQueue.from(elements); |
| 246 } | 265 } |
| 247 | 266 |
| 248 class DoubleLinkedQueueTest extends QueueTest { | 267 class DoubleLinkedQueueTest extends QueueTest { |
| 249 Queue newQueue() => new DoubleLinkedQueue(); | 268 Queue newQueue() => new DoubleLinkedQueue(); |
| 250 Queue newQueueFrom(Iterable elements) => new DoubleLinkedQueue.from(elements); | 269 Queue newQueueFrom(Iterable elements) => new DoubleLinkedQueue.from(elements); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 q.addAll(i255.skip(35).take(96)); | 338 q.addAll(i255.skip(35).take(96)); |
| 320 q.addAll(i255.skip(35 + 96)); | 339 q.addAll(i255.skip(35 + 96)); |
| 321 Expect.listEquals(i255.toList(), q.toList()); | 340 Expect.listEquals(i255.toList(), q.toList()); |
| 322 } | 341 } |
| 323 | 342 |
| 324 main() { | 343 main() { |
| 325 new DoubleLinkedQueueTest().testMain(); | 344 new DoubleLinkedQueueTest().testMain(); |
| 326 new ListQueueTest().testMain(); | 345 new ListQueueTest().testMain(); |
| 327 trickyTest(); | 346 trickyTest(); |
| 328 } | 347 } |
| OLD | NEW |