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 map_test; | 5 library map_test; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 | 7 |
8 class MapTest { | 8 class MapTest { |
9 | 9 |
10 static testMain() { | 10 static testMain() { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 Expect.equals(true, other_map.containsValue(value2)); | 145 Expect.equals(true, other_map.containsValue(value2)); |
146 Expect.equals(2, other_map.length); | 146 Expect.equals(2, other_map.length); |
147 | 147 |
148 other_map.clear(); | 148 other_map.clear(); |
149 Expect.equals(0, other_map.length); | 149 Expect.equals(0, other_map.length); |
150 | 150 |
151 // Test Collection.keys. | 151 // Test Collection.keys. |
152 void testForEachCollection(value) { | 152 void testForEachCollection(value) { |
153 other_map[value] = value; | 153 other_map[value] = value; |
154 } | 154 } |
155 Collection keys = map.keys; | 155 Iterable keys = map.keys; |
156 keys.forEach(testForEachCollection); | 156 keys.forEach(testForEachCollection); |
157 Expect.equals(true, other_map.containsKey(key1)); | 157 Expect.equals(true, other_map.containsKey(key1)); |
158 Expect.equals(true, other_map.containsKey(key2)); | 158 Expect.equals(true, other_map.containsKey(key2)); |
159 Expect.equals(true, other_map.containsValue(key1)); | 159 Expect.equals(true, other_map.containsValue(key1)); |
160 Expect.equals(true, other_map.containsValue(key2)); | 160 Expect.equals(true, other_map.containsValue(key2)); |
161 Expect.equals(true, !other_map.containsKey(value1)); | 161 Expect.equals(true, !other_map.containsKey(value1)); |
162 Expect.equals(true, !other_map.containsKey(value2)); | 162 Expect.equals(true, !other_map.containsKey(value2)); |
163 Expect.equals(true, !other_map.containsValue(value1)); | 163 Expect.equals(true, !other_map.containsValue(value1)); |
164 Expect.equals(true, !other_map.containsValue(value2)); | 164 Expect.equals(true, !other_map.containsValue(value2)); |
165 Expect.equals(2, other_map.length); | 165 Expect.equals(2, other_map.length); |
166 other_map.clear(); | 166 other_map.clear(); |
167 Expect.equals(0, other_map.length); | 167 Expect.equals(0, other_map.length); |
168 | 168 |
169 // Test Collection.values. | 169 // Test Collection.values. |
170 Collection values = map.values; | 170 Iterable values = map.values; |
171 values.forEach(testForEachCollection); | 171 values.forEach(testForEachCollection); |
172 Expect.equals(true, !other_map.containsKey(key1)); | 172 Expect.equals(true, !other_map.containsKey(key1)); |
173 Expect.equals(true, !other_map.containsKey(key2)); | 173 Expect.equals(true, !other_map.containsKey(key2)); |
174 Expect.equals(true, !other_map.containsValue(key1)); | 174 Expect.equals(true, !other_map.containsValue(key1)); |
175 Expect.equals(true, !other_map.containsValue(key2)); | 175 Expect.equals(true, !other_map.containsValue(key2)); |
176 Expect.equals(true, other_map.containsKey(value1)); | 176 Expect.equals(true, other_map.containsKey(value1)); |
177 Expect.equals(true, other_map.containsKey(value2)); | 177 Expect.equals(true, other_map.containsKey(value2)); |
178 Expect.equals(true, other_map.containsValue(value1)); | 178 Expect.equals(true, other_map.containsValue(value1)); |
179 Expect.equals(true, other_map.containsValue(value2)); | 179 Expect.equals(true, other_map.containsValue(value2)); |
180 Expect.equals(2, other_map.length); | 180 Expect.equals(2, other_map.length); |
(...skipping 23 matching lines...) Expand all Loading... |
204 | 204 |
205 static void testMapLiteral() { | 205 static void testMapLiteral() { |
206 Map m = {"a": 1, "b" : 2, "c": 3 }; | 206 Map m = {"a": 1, "b" : 2, "c": 3 }; |
207 Expect.equals(3, m.length); | 207 Expect.equals(3, m.length); |
208 int sum = 0; | 208 int sum = 0; |
209 m.forEach((a, b) { | 209 m.forEach((a, b) { |
210 sum += b; | 210 sum += b; |
211 }); | 211 }); |
212 Expect.equals(6, sum); | 212 Expect.equals(6, sum); |
213 | 213 |
214 List values = m.keys; | 214 List values = m.keys.toList(); |
215 Expect.equals(3, values.length); | 215 Expect.equals(3, values.length); |
216 String first = values[0]; | 216 String first = values[0]; |
217 String second = values[1]; | 217 String second = values[1]; |
218 String third = values[2]; | 218 String third = values[2]; |
219 String all = "${first}${second}${third}"; | 219 String all = "${first}${second}${third}"; |
220 Expect.equals(3, all.length); | 220 Expect.equals(3, all.length); |
221 Expect.equals(true, all.contains("a", 0)); | 221 Expect.equals(true, all.contains("a", 0)); |
222 Expect.equals(true, all.contains("b", 0)); | 222 Expect.equals(true, all.contains("b", 0)); |
223 Expect.equals(true, all.contains("c", 0)); | 223 Expect.equals(true, all.contains("c", 0)); |
224 } | 224 } |
(...skipping 16 matching lines...) Expand all Loading... |
241 m.remove("a"); | 241 m.remove("a"); |
242 Expect.equals(2, m.length); | 242 Expect.equals(2, m.length); |
243 Expect.equals(null, m["a"]); | 243 Expect.equals(null, m["a"]); |
244 Expect.equals(false, m.containsKey("a")); | 244 Expect.equals(false, m.containsKey("a")); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 main() { | 248 main() { |
249 MapTest.testMain(); | 249 MapTest.testMain(); |
250 } | 250 } |
OLD | NEW |