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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/set_iterator_test.dart ('k') | tests/corelib/sort_helper.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 class SetTest { 5 class SetTest {
6 6
7 static testMain() { 7 static testMain() {
8 Set set = new Set(); 8 Set set = new Set();
9 Expect.equals(0, set.length); 9 Expect.equals(0, set.length);
10 set.add(1); 10 set.add(1);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum); 44 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum);
45 45
46 Expect.equals(true, set.isSubsetOf(set)); 46 Expect.equals(true, set.isSubsetOf(set));
47 Expect.equals(true, set.containsAll(set)); 47 Expect.equals(true, set.containsAll(set));
48 48
49 // Test Set.map. 49 // Test Set.map.
50 testMap(int val) { 50 testMap(int val) {
51 return val * val; 51 return val * val;
52 } 52 }
53 53
54 Set mapped = set.map(testMap); 54 Set mapped = set.mappedBy(testMap).toSet();
55 Expect.equals(10, mapped.length); 55 Expect.equals(10, mapped.length);
56 56
57 Expect.equals(true, mapped.contains(0)); 57 Expect.equals(true, mapped.contains(0));
58 Expect.equals(true, mapped.contains(1)); 58 Expect.equals(true, mapped.contains(1));
59 Expect.equals(true, mapped.contains(4)); 59 Expect.equals(true, mapped.contains(4));
60 Expect.equals(true, mapped.contains(9)); 60 Expect.equals(true, mapped.contains(9));
61 Expect.equals(true, mapped.contains(16)); 61 Expect.equals(true, mapped.contains(16));
62 Expect.equals(true, mapped.contains(25)); 62 Expect.equals(true, mapped.contains(25));
63 Expect.equals(true, mapped.contains(36)); 63 Expect.equals(true, mapped.contains(36));
64 Expect.equals(true, mapped.contains(49)); 64 Expect.equals(true, mapped.contains(49));
65 Expect.equals(true, mapped.contains(64)); 65 Expect.equals(true, mapped.contains(64));
66 Expect.equals(true, mapped.contains(81)); 66 Expect.equals(true, mapped.contains(81));
67 67
68 sum = 0; 68 sum = 0;
69 set.forEach(testForEach); 69 set.forEach(testForEach);
70 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum); 70 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum);
71 71
72 sum = 0; 72 sum = 0;
73 73
74 mapped.forEach(testForEach); 74 mapped.forEach(testForEach);
75 Expect.equals(1 + 2 + 5 + 10 + 17 + 26 + 37 + 50 + 65 + 82, sum); 75 Expect.equals(1 + 2 + 5 + 10 + 17 + 26 + 37 + 50 + 65 + 82, sum);
76 76
77 // Test Set.filter. 77 // Test Set.filter.
78 testFilter(int val) { 78 testFilter(int val) {
79 return val.isEven; 79 return val.isEven;
80 } 80 }
81 81
82 Set filtered = set.filter(testFilter); 82 Set filtered = set.where(testFilter).toSet();
83 83
84 Expect.equals(5, filtered.length); 84 Expect.equals(5, filtered.length);
85 85
86 Expect.equals(true, filtered.contains(0)); 86 Expect.equals(true, filtered.contains(0));
87 Expect.equals(true, filtered.contains(2)); 87 Expect.equals(true, filtered.contains(2));
88 Expect.equals(true, filtered.contains(4)); 88 Expect.equals(true, filtered.contains(4));
89 Expect.equals(true, filtered.contains(6)); 89 Expect.equals(true, filtered.contains(6));
90 Expect.equals(true, filtered.contains(8)); 90 Expect.equals(true, filtered.contains(8));
91 91
92 sum = 0; 92 sum = 0;
(...skipping 12 matching lines...) Expand all
105 Expect.equals(true, filtered.every(testEvery)); 105 Expect.equals(true, filtered.every(testEvery));
106 106
107 filtered.add(10); 107 filtered.add(10);
108 Expect.equals(false, filtered.every(testEvery)); 108 Expect.equals(false, filtered.every(testEvery));
109 109
110 // Test Set.some. 110 // Test Set.some.
111 testSome(int val) { 111 testSome(int val) {
112 return (val == 4); 112 return (val == 4);
113 } 113 }
114 114
115 Expect.equals(true, set.some(testSome)); 115 Expect.equals(true, set.any(testSome));
116 Expect.equals(true, filtered.some(testSome)); 116 Expect.equals(true, filtered.any(testSome));
117 filtered.remove(4); 117 filtered.remove(4);
118 Expect.equals(false, filtered.some(testSome)); 118 Expect.equals(false, filtered.any(testSome));
119 119
120 // Test Set.intersection. 120 // Test Set.intersection.
121 Set intersection = set.intersection(filtered); 121 Set intersection = set.intersection(filtered);
122 Expect.equals(true, set.contains(0)); 122 Expect.equals(true, set.contains(0));
123 Expect.equals(true, set.contains(2)); 123 Expect.equals(true, set.contains(2));
124 Expect.equals(true, set.contains(6)); 124 Expect.equals(true, set.contains(6));
125 Expect.equals(true, set.contains(8)); 125 Expect.equals(true, set.contains(8));
126 Expect.equals(false, intersection.contains(1)); 126 Expect.equals(false, intersection.contains(1));
127 Expect.equals(false, intersection.contains(3)); 127 Expect.equals(false, intersection.contains(3));
128 Expect.equals(false, intersection.contains(4)); 128 Expect.equals(false, intersection.contains(4));
129 Expect.equals(false, intersection.contains(5)); 129 Expect.equals(false, intersection.contains(5));
130 Expect.equals(false, intersection.contains(7)); 130 Expect.equals(false, intersection.contains(7));
131 Expect.equals(false, intersection.contains(9)); 131 Expect.equals(false, intersection.contains(9));
132 Expect.equals(false, intersection.contains(10)); 132 Expect.equals(false, intersection.contains(10));
133 Expect.equals(4, intersection.length); 133 Expect.equals(4, intersection.length);
134 134
135 Expect.equals(true, set.containsAll(intersection)); 135 Expect.equals(true, set.containsAll(intersection));
136 Expect.equals(true, filtered.containsAll(intersection)); 136 Expect.equals(true, filtered.containsAll(intersection));
137 Expect.equals(true, intersection.isSubsetOf(set)); 137 Expect.equals(true, intersection.isSubsetOf(set));
138 Expect.equals(true, intersection.isSubsetOf(filtered)); 138 Expect.equals(true, intersection.isSubsetOf(filtered));
139 139
140 // Test Set.addAll. 140 // Test Set.addAll.
141 List list = new List(10); 141 List list = new List.fixedLength(10);
142 for (int i = 0; i < 10; i++) { 142 for (int i = 0; i < 10; i++) {
143 list[i] = i + 10; 143 list[i] = i + 10;
144 } 144 }
145 set.addAll(list); 145 set.addAll(list);
146 Expect.equals(20, set.length); 146 Expect.equals(20, set.length);
147 for (int i = 0; i < 20; i++) { 147 for (int i = 0; i < 20; i++) {
148 Expect.equals(true, set.contains(i)); 148 Expect.equals(true, set.contains(i));
149 } 149 }
150 150
151 // Test Set.removeAll 151 // Test Set.removeAll
(...skipping 10 matching lines...) Expand all
162 set.clear(); 162 set.clear();
163 Expect.equals(0, set.length); 163 Expect.equals(0, set.length);
164 set.add(11); 164 set.add(11);
165 Expect.equals(1, set.length); 165 Expect.equals(1, set.length);
166 } 166 }
167 } 167 }
168 168
169 main() { 169 main() {
170 SetTest.testMain(); 170 SetTest.testMain();
171 } 171 }
OLDNEW
« no previous file with comments | « tests/corelib/set_iterator_test.dart ('k') | tests/corelib/sort_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698