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

Side by Side Diff: tests/corelib/src/MapsTest.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, 7 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 #library("MapsTest.dart");
6 #import("dart:coreimpl");
7
8 main() {
9 final key1 = "key1";
10 final key2 = "key2";
11 final key3 = "key3";
12 final key4 = "key4";
13 final key5 = "key5";
14 final key6 = "key6";
15 final key7 = "key7";
16 final key8 = "key8";
17
18 final value1 = 10;
19 final value2 = 20;
20 final value3 = 30;
21 final value4 = 40;
22 final value5 = 50;
23 final value6 = 60;
24 final value7 = 70;
25 final value8 = 80;
26
27 Map map = new Map();
28
29 map[key1] = value1;
30 map[key1] = value2;
31 Expect.equals(false, Maps.containsKey(map, key2));
32 Expect.equals(1, Maps.length(map));
33
34 map[key1] = value1;
35 // Add enough entries to make sure the table grows.
36 map[key2] = value2;
37 Expect.equals(2, Maps.length(map));
38 map[key3] = value3;
39 map[key4] = value4;
40 map[key5] = value5;
41 map[key6] = value6;
42 map[key7] = value7;
43 map[key8] = value8;
44 Expect.equals(8, Maps.length(map));
45
46 map.remove(key4);
47 Expect.equals(false, Maps.containsKey(map, key4));
48 Expect.equals(7, Maps.length(map));
49
50 // Test clearing the table.
51 Maps.clear(map);
52 Expect.equals(0, Maps.length(map));
53 Expect.equals(false, Maps.containsKey(map, key1));
54 Expect.equals(false, map.containsKey(key1));
55 Expect.equals(false, Maps.containsKey(map, key2));
56 Expect.equals(false, map.containsKey(key2));
57 Expect.equals(false, Maps.containsKey(map, key3));
58 Expect.equals(false, map.containsKey(key3));
59 Expect.equals(false, Maps.containsKey(map, key4));
60 Expect.equals(false, map.containsKey(key4));
61 Expect.equals(false, Maps.containsKey(map, key5));
62 Expect.equals(false, map.containsKey(key5));
63 Expect.equals(false, Maps.containsKey(map, key6));
64 Expect.equals(false, map.containsKey(key6));
65 Expect.equals(false, Maps.containsKey(map, key7));
66 Expect.equals(false, map.containsKey(key7));
67 Expect.equals(false, Maps.containsKey(map, key8));
68 Expect.equals(false, map.containsKey(key8));
69
70 // Test adding and removing again.
71 map[key1] = value1;
72 Expect.equals(1, Maps.length(map));
73 map[key2] = value2;
74 Expect.equals(2, Maps.length(map));
75 map[key3] = value3;
76 map.remove(key3);
77 Expect.equals(2, Maps.length(map));
78 map[key4] = value4;
79 map.remove(key4);
80 Expect.equals(2, Maps.length(map));
81 map[key5] = value5;
82 map.remove(key5);
83 Expect.equals(2, Maps.length(map));
84 map[key6] = value6;
85 map.remove(key6);
86 Expect.equals(2, Maps.length(map));
87 map[key7] = value7;
88 map.remove(key7);
89 Expect.equals(2, Maps.length(map));
90 map[key8] = value8;
91 map.remove(key8);
92 Expect.equals(2, Maps.length(map));
93
94 Expect.equals(true, Maps.containsKey(map, key1));
95 Expect.equals(true, Maps.containsValue(map, value1));
96
97 // Test Map.forEach.
98 Map other_map = new Map();
99 void testForEachMap(key, value) {
100 other_map[key] = value;
101 }
102 Maps.forEach(map, testForEachMap);
103 Expect.equals(true, other_map.containsKey(key1));
104 Expect.equals(true, other_map.containsKey(key2));
105 Expect.equals(true, other_map.containsValue(value1));
106 Expect.equals(true, other_map.containsValue(value2));
107 Expect.equals(2, Maps.length(other_map));
108
109 // Test Collection.getValues.
110 void testForEachCollection(value) {
111 other_map[value] = value;
112 }
113 Collection values = Maps.getValues(map);
114 other_map = new Map();
115 values.forEach(testForEachCollection);
116 Expect.equals(true, !other_map.containsKey(key1));
117 Expect.equals(true, !other_map.containsKey(key2));
118 Expect.equals(true, !other_map.containsValue(key1));
119 Expect.equals(true, !other_map.containsValue(key2));
120 Expect.equals(true, other_map.containsKey(value1));
121 Expect.equals(true, other_map.containsKey(value2));
122 Expect.equals(true, other_map.containsValue(value1));
123 Expect.equals(true, other_map.containsValue(value2));
124 Expect.equals(2, other_map.length);
125 other_map.clear();
126
127 // Test Map.putIfAbsent.
128 map.clear();
129 Expect.equals(false, Maps.containsKey(map, key1));
130 Maps.putIfAbsent(map, key1, () => 10);
131 Expect.equals(true, map.containsKey(key1));
132 Expect.equals(10, map[key1]);
133 Expect.equals(10, Maps.putIfAbsent(map, key1, () => 11));
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698