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

Side by Side Diff: test/codegen/corelib/linked_hash_map_test.dart

Issue 1945153002: Add corelib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: error_test and range_error_test now pass Created 4 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
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 library linkedHashMap.test;
7 import "package:expect/expect.dart";
8 import 'dart:collection' show LinkedHashMap;
9
10 class LinkedHashMapTest {
11 static void testMain() {
12 Map map = new LinkedHashMap();
13 map["a"] = 1;
14 map["b"] = 2;
15 map["c"] = 3;
16 map["d"] = 4;
17 map["e"] = 5;
18
19 List<String> keys = new List<String>(5);
20 List<int> values = new List<int>(5);
21
22 int index;
23
24 clear() {
25 index = 0;
26 for (int i = 0; i < keys.length; i++) {
27 keys[i] = null;
28 values[i] = null;
29 }
30 }
31
32 verifyKeys(List<String> correctKeys) {
33 for (int i = 0; i < correctKeys.length; i++) {
34 Expect.equals(correctKeys[i], keys[i]);
35 }
36 }
37
38 verifyValues(List<int> correctValues) {
39 for (int i = 0; i < correctValues.length; i++) {
40 Expect.equals(correctValues[i], values[i]);
41 }
42 }
43
44 testForEachMap(Object key, Object value) {
45 Expect.equals(map[key], value);
46 keys[index] = key;
47 values[index] = value;
48 index++;
49 }
50
51 testForEachValue(Object v) {
52 values[index++] = v;
53 }
54
55 testForEachKey(Object v) {
56 keys[index++] = v;
57 }
58
59 final keysInOrder = const ["a", "b", "c", "d", "e"];
60 final valuesInOrder = const [1, 2, 3, 4, 5];
61
62 clear();
63 map.forEach(testForEachMap);
64 verifyKeys(keysInOrder);
65 verifyValues(valuesInOrder);
66
67 clear();
68 map.keys.forEach(testForEachKey);
69 verifyKeys(keysInOrder);
70
71 clear();
72 map.values.forEach(testForEachValue);
73 verifyValues(valuesInOrder);
74
75 // Remove and then insert.
76 map.remove("b");
77 map["b"] = 6;
78 final keysAfterBMove = const ["a", "c", "d", "e", "b"];
79 final valuesAfterBMove = const [1, 3, 4, 5, 6];
80
81
82 clear();
83 map.forEach(testForEachMap);
84 verifyKeys(keysAfterBMove);
85 verifyValues(valuesAfterBMove);
86
87 clear();
88 map.keys.forEach(testForEachKey);
89 verifyKeys(keysAfterBMove);
90
91 clear();
92 map.values.forEach(testForEachValue);
93 verifyValues(valuesAfterBMove);
94
95 // Update.
96 map["a"] = 0;
97 final valuesAfterAUpdate = const [0, 3, 4, 5, 6];
98
99 clear();
100 map.forEach(testForEachMap);
101 verifyKeys(keysAfterBMove);
102 verifyValues(valuesAfterAUpdate);
103
104 clear();
105 map.keys.forEach(testForEachKey);
106 verifyKeys(keysAfterBMove);
107
108 clear();
109 map.values.forEach(testForEachValue);
110 verifyValues(valuesAfterAUpdate);
111 }
112 }
113
114 main() {
115 LinkedHashMapTest.testMain();
116 }
OLDNEW
« no previous file with comments | « test/codegen/corelib/linked_hash_map_from_iterables_test.dart ('k') | test/codegen/corelib/list_as_map_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698