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

Side by Side Diff: tests/corelib/src/LinkedHashMapTest.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 // Dart test for linked hash-maps.
6
7 class LinkedHashMapTest {
8 static void testMain() {
9 Map map = new LinkedHashMap();
10 map["a"] = 1;
11 map["b"] = 2;
12 map["c"] = 3;
13 map["d"] = 4;
14 map["e"] = 5;
15
16 List<String> keys = new List<String>(5);
17 List<int> values = new List<int>(5);
18
19 int index;
20
21 clear() {
22 index = 0;
23 for (int i = 0; i < keys.length; i++) {
24 keys[i] = null;
25 values[i] = null;
26 }
27 }
28
29 verifyKeys(List<String> correctKeys) {
30 for (int i = 0; i < correctKeys.length; i++) {
31 Expect.equals(correctKeys[i], keys[i]);
32 }
33 }
34
35 verifyValues(List<int> correctValues) {
36 for (int i = 0; i < correctValues.length; i++) {
37 Expect.equals(correctValues[i], values[i]);
38 }
39 }
40
41 testForEachMap(Object key, Object value) {
42 Expect.equals(map[key], value);
43 keys[index] = key;
44 values[index] = value;
45 index++;
46 }
47
48 testForEachValue(Object v) {
49 values[index++] = v;
50 }
51
52 testForEachKey(Object v) {
53 keys[index++] = v;
54 }
55
56 final keysInOrder = const ["a", "b", "c", "d", "e"];
57 final valuesInOrder = const [1, 2, 3, 4, 5];
58
59 clear();
60 map.forEach(testForEachMap);
61 verifyKeys(keysInOrder);
62 verifyValues(valuesInOrder);
63
64 clear();
65 map.getKeys().forEach(testForEachKey);
66 verifyKeys(keysInOrder);
67
68 clear();
69 map.getValues().forEach(testForEachValue);
70 verifyValues(valuesInOrder);
71
72 // Remove and then insert.
73 map.remove("b");
74 map["b"] = 6;
75 final keysAfterBMove = const ["a", "c", "d", "e", "b"];
76 final valuesAfterBMove = const [1, 3, 4, 5, 6];
77
78
79 clear();
80 map.forEach(testForEachMap);
81 verifyKeys(keysAfterBMove);
82 verifyValues(valuesAfterBMove);
83
84 clear();
85 map.getKeys().forEach(testForEachKey);
86 verifyKeys(keysAfterBMove);
87
88 clear();
89 map.getValues().forEach(testForEachValue);
90 verifyValues(valuesAfterBMove);
91
92 // Update.
93 map["a"] = 0;
94 final valuesAfterAUpdate = const [0, 3, 4, 5, 6];
95
96 clear();
97 map.forEach(testForEachMap);
98 verifyKeys(keysAfterBMove);
99 verifyValues(valuesAfterAUpdate);
100
101 clear();
102 map.getKeys().forEach(testForEachKey);
103 verifyKeys(keysAfterBMove);
104
105 clear();
106 map.getValues().forEach(testForEachValue);
107 verifyValues(valuesAfterAUpdate);
108 }
109 }
110
111 main() {
112 LinkedHashMapTest.testMain();
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698