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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 queue.remove(10); | 224 queue.remove(10); |
225 testLength(29, queue); | 225 testLength(29, queue); |
226 | 226 |
227 queue.removeAll([4, 6]); | 227 queue.removeAll([4, 6]); |
228 testLength(23, queue); | 228 testLength(23, queue); |
229 | 229 |
230 queue.retainAll([1, 3, 5, 7, 9, 10]); // Remove 2 and 8. | 230 queue.retainAll([1, 3, 5, 7, 9, 10]); // Remove 2 and 8. |
231 testLength(17, queue); | 231 testLength(17, queue); |
232 | 232 |
233 queue.removeMatching((x) => x == 7); | 233 queue.removeWhere((x) => x == 7); |
234 testLength(14, queue); | 234 testLength(14, queue); |
235 | 235 |
236 queue.retainMatching((x) => x != 3); | 236 queue.retainWhere((x) => x != 3); |
237 testLength(11, queue); | 237 testLength(11, queue); |
238 | 238 |
239 Expect.listEquals([9, 1, 5, 9, 10, 1, 5, 9, 10, 1, 5], queue.toList()); | 239 Expect.listEquals([9, 1, 5, 9, 10, 1, 5, 9, 10, 1, 5], queue.toList()); |
240 } | 240 } |
241 | 241 |
242 void testLarge() { | 242 void testLarge() { |
243 int N = 10000; | 243 int N = 10000; |
244 Set set = new Set(); | 244 Set set = new Set(); |
245 | 245 |
246 Queue queue = newQueue(); | 246 Queue queue = newQueue(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 Expect.equals(i, q.removeFirst()); | 339 Expect.equals(i, q.removeFirst()); |
340 } | 340 } |
341 q.add(255); | 341 q.add(255); |
342 for (int i = 0; i < 127; i++) { | 342 for (int i = 0; i < 127; i++) { |
343 q.add(i); | 343 q.add(i); |
344 } | 344 } |
345 | 345 |
346 Expect.equals(255, q.length); | 346 Expect.equals(255, q.length); |
347 | 347 |
348 // Remove element at end of internal buffer. | 348 // Remove element at end of internal buffer. |
349 q.removeMatching((v) => v == 255); | 349 q.removeWhere((v) => v == 255); |
350 // Remove element at beginning of internal buffer. | 350 // Remove element at beginning of internal buffer. |
351 q.removeMatching((v) => v == 0); | 351 q.removeWhere((v) => v == 0); |
352 // Remove element at both ends of internal buffer. | 352 // Remove element at both ends of internal buffer. |
353 q.removeMatching((v) => v == 254 || v == 1); | 353 q.removeWhere((v) => v == 254 || v == 1); |
354 | 354 |
355 Expect.equals(251, q.length); | 355 Expect.equals(251, q.length); |
356 | 356 |
357 Iterable i255 = new Iterable.generate(255, (x) => x); | 357 Iterable i255 = new Iterable.generate(255, (x) => x); |
358 | 358 |
359 q = new ListQueue(); | 359 q = new ListQueue(); |
360 q.addAll(i255); | 360 q.addAll(i255); |
361 Expect.listEquals(i255.toList(), q.toList()); | 361 Expect.listEquals(i255.toList(), q.toList()); |
362 | 362 |
363 q = new ListQueue(); | 363 q = new ListQueue(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 Expect.equals(null, entry2); | 405 Expect.equals(null, entry2); |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 main() { | 410 main() { |
411 new DoubleLinkedQueueTest().testMain(); | 411 new DoubleLinkedQueueTest().testMain(); |
412 new ListQueueTest().testMain(); | 412 new ListQueueTest().testMain(); |
413 } | 413 } |
OLD | NEW |