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

Side by Side Diff: tests/corelib/src/MapFromTest.dart

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

Powered by Google App Engine
This is Rietveld 408576698