Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tests/corelib/queue_test.dart

Issue 14173003: Remove Collection, Collections and clean up List/Set/Queue implementations of retain/remove. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/corelib/iterable_contains_test.dart ('k') | tests/corelib/set_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 219
220 for (int i = 1; i <= 5; i++) { 220 for (int i = 1; i <= 5; i++) {
221 Expect.equals(11 - i, queue.removeLast()); 221 Expect.equals(11 - i, queue.removeLast());
222 testLength(35 - i, queue); 222 testLength(35 - i, queue);
223 } 223 }
224 224
225 queue.remove(10); 225 queue.remove(10);
226 testLength(29, queue); 226 testLength(29, queue);
227 227
228 queue.removeAll([4, 6]); 228 queue.removeWhere((x) => x == 7);
229 testLength(26, queue);
230
231 queue.retainWhere((x) => x != 3);
229 testLength(23, queue); 232 testLength(23, queue);
230 233
231 queue.retainAll([1, 3, 5, 7, 9, 10]); // Remove 2 and 8. 234 Expect.listEquals(
232 testLength(17, queue); 235 [6, 8, 9, 1, 2, 4, 5, 6, 8, 9, 10, 1, 2, 4, 5, 6, 8, 9, 10, 1, 2, 4, 5],
233 236 queue.toList());
234 queue.removeWhere((x) => x == 7);
235 testLength(14, queue);
236
237 queue.retainWhere((x) => x != 3);
238 testLength(11, queue);
239
240 Expect.listEquals([9, 1, 5, 9, 10, 1, 5, 9, 10, 1, 5], queue.toList());
241 } 237 }
242 238
243 void testLarge() { 239 void testLarge() {
244 int N = 10000; 240 int N = 10000;
245 Set set = new Set(); 241 Set set = new Set();
246 242
247 Queue queue = newQueue(); 243 Queue queue = newQueue();
248 Expect.isTrue(queue.isEmpty); 244 Expect.isTrue(queue.isEmpty);
249 245
250 for (int i = 0; i < N; i++) { 246 for (int i = 0; i < N; i++) {
(...skipping 13 matching lines...) Expand all
264 Expect.equals(-i, mapped.first); 260 Expect.equals(-i, mapped.first);
265 Expect.equals(i + 1, skip1.first); 261 Expect.equals(i + 1, skip1.first);
266 Expect.equals(i, queue.removeFirst()); 262 Expect.equals(i, queue.removeFirst());
267 Expect.equals(i + 1, take1.first); 263 Expect.equals(i + 1, take1.first);
268 Expect.equals(-i - 1, mapped.first); 264 Expect.equals(-i - 1, mapped.first);
269 Expect.equals(N - 1 - i, queue.last); 265 Expect.equals(N - 1 - i, queue.last);
270 Expect.equals(N - 1 - i, queue.removeLast()); 266 Expect.equals(N - 1 - i, queue.removeLast());
271 } 267 }
272 Expect.equals(N - 1000, queue.length); 268 Expect.equals(N - 1000, queue.length);
273 269
274 queue.retainAll(set);
275 Expect.equals(N - 1000, queue.length);
276
277 queue.remove(N >> 1); 270 queue.remove(N >> 1);
278 Expect.equals(N - 1001, queue.length); 271 Expect.equals(N - 1001, queue.length);
279 272
280 queue.removeAll(set); 273 queue.clear();
281 Expect.equals(0, queue.length); 274 Expect.equals(0, queue.length);
282 Expect.isTrue(queue.isEmpty); 275 Expect.isTrue(queue.isEmpty);
283 276
284 queue.addAll(set); 277 queue.addAll(set);
285 Expect.equals(N, queue.length); 278 Expect.equals(N, queue.length);
286 Expect.isFalse(queue.isEmpty); 279 Expect.isFalse(queue.isEmpty);
287 280
288 // Iterate. 281 // Iterate.
289 for (var element in queue) { 282 for (var element in queue) {
290 Expect.isTrue(set.contains(element)); 283 Expect.isTrue(set.contains(element));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 398 }
406 Expect.equals(null, entry2); 399 Expect.equals(null, entry2);
407 } 400 }
408 } 401 }
409 402
410 403
411 main() { 404 main() {
412 new DoubleLinkedQueueTest().testMain(); 405 new DoubleLinkedQueueTest().testMain();
413 new ListQueueTest().testMain(); 406 new ListQueueTest().testMain();
414 } 407 }
OLDNEW
« no previous file with comments | « tests/corelib/iterable_contains_test.dart ('k') | tests/corelib/set_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698