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

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

Issue 12049065: Fix bugs in GrowableList.remove*. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Fix typo in filtered list. Created 7 years, 10 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 testRemove(Collection base) {
6 int length = base.length;
7 for (int i = 0; i < length; i++) {
8 Expect.isFalse(base.isEmpty);
9 base.remove(base.first);
10 }
11 Expect.isTrue(base.isEmpty);
12 }
13
14 testRemoveAll(Collection base, Iterable removes) {
15 Set retained = new Set();
16 for (var element in base) {
17 if (!removes.contains(element)) {
18 retained.add(element);
19 }
20 }
21 String name = "$base.removeAll($removes) -> $retained";
22 base.removeAll(removes);
23 for (var value in base) {
24 Expect.isFalse(removes.contains(value), "$name: Found $value");
25 }
26 for (var value in retained) {
27 Expect.isTrue(base.contains(value), "$name: Found $value");
28 }
29 }
30
31 testRetainAll(Collection base, Iterable retains) {
32 Set retained = new Set();
33 for (var element in base) {
34 if (retains.contains(element)) {
35 retained.add(element);
36 }
37 }
38 String name = "$base.retainAll($retains) -> $retained";
39 base.retainAll(retains);
40 for (var value in base) {
41 Expect.isTrue(retains.contains(value), "$name: Found $value");
42 }
43 for (var value in retained) {
44 Expect.isTrue(base.contains(value), "$name: Found $value");
45 }
46 }
47
48 testRemoveMatching(Collection base, bool test(value)) {
49 Set retained = new Set();
50 for (var element in base) {
51 if (!test(element)) {
52 retained.add(element);
53 }
54 }
55 String name = "$base.removeMatching(...) -> $retained";
56 base.removeMatching(test);
57 for (var value in base) {
58 Expect.isFalse(test(value), "$name: Found $value");
59 }
60 for (var value in retained) {
61 Expect.isTrue(base.contains(value), "$name: Found $value");
62 }
63 }
64
65 testRetainMatching(Collection base, bool test(value)) {
66 Set retained = new Set();
67 for (var element in base) {
68 if (test(element)) {
69 retained.add(element);
70 }
71 }
72 String name = "$base.retainMatching(...) -> $retained";
73 base.retainMatching(test);
74 for (var value in base) {
75 Expect.isTrue(test(value), "$name: Found $value");
76 }
77 for (var value in retained) {
78 Expect.isTrue(base.contains(value), "$name: Found $value");
79 }
80 }
81
82 void main() {
83 var collections = [
84 [], [1], [2], [1, 2], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
85 [1, 3, 5, 7, 9], [2, 4, 6, 8, 10]
86 ];
87 for (var base in collections) {
88 for (var delta in collections) {
89 testRemove(base.toList());
90 testRemove(base.toSet());
91
92 var deltaSet = delta.toSet();
93 testRemoveAll(base.toList(), delta);
94 testRemoveAll(base.toList(), deltaSet);
95 testRetainAll(base.toList(), delta);
96 testRetainAll(base.toList(), deltaSet);
97 testRemoveMatching(base.toList(), deltaSet.contains);
98 testRetainMatching(base.toList(), (e) => !deltaSet.contains(e));
99
100 testRemoveAll(base.toSet(), delta);
101 testRemoveAll(base.toSet(), deltaSet);
102 testRetainAll(base.toSet(), delta);
103 testRetainAll(base.toSet(), deltaSet);
104 testRemoveMatching(base.toSet(), deltaSet.contains);
105 testRetainMatching(base.toSet(), (e) => !deltaSet.contains(e));
106 }
107 }
108 }
109
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698