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

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

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month 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/linked_hash_map_test.dart ('k') | tests/corelib/map_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 main() { 5 main() {
6 testWithConstMap(); 6 testWithConstMap();
7 testWithNonConstMap(); 7 testWithNonConstMap();
8 testWithLinkedMap(); 8 testWithLinkedMap();
9 } 9 }
10 10
11 testWithConstMap() { 11 testWithConstMap() {
12 var map = const { 'b': 42, 'a': 43 }; 12 var map = const { 'b': 42, 'a': 43 };
13 var otherMap = new Map.from(map); 13 var otherMap = new Map.from(map);
14 Expect.isTrue(otherMap is Map); 14 Expect.isTrue(otherMap is Map);
15 Expect.isTrue(otherMap is HashMap); 15 Expect.isTrue(otherMap is HashMap);
16 Expect.isTrue(otherMap is !LinkedHashMap); 16 Expect.isTrue(otherMap is !LinkedHashMap);
17 17
18 Expect.equals(2, otherMap.length); 18 Expect.equals(2, otherMap.length);
19 Expect.equals(2, otherMap.getKeys().length); 19 Expect.equals(2, otherMap.keys.length);
20 Expect.equals(2, otherMap.getValues().length); 20 Expect.equals(2, otherMap.values.length);
21 21
22 var count = (map) { 22 var count = (map) {
23 int count = 0; 23 int count = 0;
24 map.forEach((a, b) { count += b; }); 24 map.forEach((a, b) { count += b; });
25 return count; 25 return count;
26 }; 26 };
27 27
28 Expect.equals(42 + 43, count(map)); 28 Expect.equals(42 + 43, count(map));
29 Expect.equals(count(map), count(otherMap)); 29 Expect.equals(count(map), count(otherMap));
30 } 30 }
31 31
32 testWithNonConstMap() { 32 testWithNonConstMap() {
33 var map = { 'b': 42, 'a': 43 }; 33 var map = { 'b': 42, 'a': 43 };
34 var otherMap = new Map.from(map); 34 var otherMap = new Map.from(map);
35 Expect.isTrue(otherMap is Map); 35 Expect.isTrue(otherMap is Map);
36 Expect.isTrue(otherMap is HashMap); 36 Expect.isTrue(otherMap is HashMap);
37 Expect.isTrue(otherMap is !LinkedHashMap); 37 Expect.isTrue(otherMap is !LinkedHashMap);
38 38
39 Expect.equals(2, otherMap.length); 39 Expect.equals(2, otherMap.length);
40 Expect.equals(2, otherMap.getKeys().length); 40 Expect.equals(2, otherMap.keys.length);
41 Expect.equals(2, otherMap.getValues().length); 41 Expect.equals(2, otherMap.values.length);
42 42
43 int count(map) { 43 int count(map) {
44 int count = 0; 44 int count = 0;
45 map.forEach((a, b) { count += b; }); 45 map.forEach((a, b) { count += b; });
46 return count; 46 return count;
47 }; 47 };
48 48
49 Expect.equals(42 + 43, count(map)); 49 Expect.equals(42 + 43, count(map));
50 Expect.equals(count(map), count(otherMap)); 50 Expect.equals(count(map), count(otherMap));
51 51
52 // Test that adding to the original map does not change otherMap. 52 // Test that adding to the original map does not change otherMap.
53 map['c'] = 44; 53 map['c'] = 44;
54 Expect.equals(3, map.length); 54 Expect.equals(3, map.length);
55 Expect.equals(2, otherMap.length); 55 Expect.equals(2, otherMap.length);
56 Expect.equals(2, otherMap.getKeys().length); 56 Expect.equals(2, otherMap.keys.length);
57 Expect.equals(2, otherMap.getValues().length); 57 Expect.equals(2, otherMap.values.length);
58 58
59 // Test that adding to otherMap does not change the original map. 59 // Test that adding to otherMap does not change the original map.
60 otherMap['c'] = 44; 60 otherMap['c'] = 44;
61 Expect.equals(3, map.length); 61 Expect.equals(3, map.length);
62 Expect.equals(3, otherMap.length); 62 Expect.equals(3, otherMap.length);
63 Expect.equals(3, otherMap.getKeys().length); 63 Expect.equals(3, otherMap.keys.length);
64 Expect.equals(3, otherMap.getValues().length); 64 Expect.equals(3, otherMap.values.length);
65 } 65 }
66 66
67 testWithLinkedMap() { 67 testWithLinkedMap() {
68 var map = const { 'b': 1, 'a': 2, 'c': 3 }; 68 var map = const { 'b': 1, 'a': 2, 'c': 3 };
69 var otherMap = new LinkedHashMap.from(map); 69 var otherMap = new LinkedHashMap.from(map);
70 Expect.isTrue(otherMap is Map); 70 Expect.isTrue(otherMap is Map);
71 Expect.isTrue(otherMap is HashMap); 71 Expect.isTrue(otherMap is HashMap);
72 Expect.isTrue(otherMap is LinkedHashMap); 72 Expect.isTrue(otherMap is LinkedHashMap);
73 var i = 1; 73 var i = 1;
74 for (var val in map.getValues()) { 74 for (var val in map.values) {
75 Expect.equals(i++, val); 75 Expect.equals(i++, val);
76 } 76 }
77 } 77 }
OLDNEW
« no previous file with comments | « tests/corelib/linked_hash_map_test.dart ('k') | tests/corelib/map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698