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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: test/codegen/corelib/linked_hash_map_test.dart
diff --git a/test/codegen/corelib/linked_hash_map_test.dart b/test/codegen/corelib/linked_hash_map_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..dfefca45be9d888c9a56d2191f15c43948b26aba
--- /dev/null
+++ b/test/codegen/corelib/linked_hash_map_test.dart
@@ -0,0 +1,116 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Dart test for linked hash-maps.
+library linkedHashMap.test;
+import "package:expect/expect.dart";
+import 'dart:collection' show LinkedHashMap;
+
+class LinkedHashMapTest {
+ static void testMain() {
+ Map map = new LinkedHashMap();
+ map["a"] = 1;
+ map["b"] = 2;
+ map["c"] = 3;
+ map["d"] = 4;
+ map["e"] = 5;
+
+ List<String> keys = new List<String>(5);
+ List<int> values = new List<int>(5);
+
+ int index;
+
+ clear() {
+ index = 0;
+ for (int i = 0; i < keys.length; i++) {
+ keys[i] = null;
+ values[i] = null;
+ }
+ }
+
+ verifyKeys(List<String> correctKeys) {
+ for (int i = 0; i < correctKeys.length; i++) {
+ Expect.equals(correctKeys[i], keys[i]);
+ }
+ }
+
+ verifyValues(List<int> correctValues) {
+ for (int i = 0; i < correctValues.length; i++) {
+ Expect.equals(correctValues[i], values[i]);
+ }
+ }
+
+ testForEachMap(Object key, Object value) {
+ Expect.equals(map[key], value);
+ keys[index] = key;
+ values[index] = value;
+ index++;
+ }
+
+ testForEachValue(Object v) {
+ values[index++] = v;
+ }
+
+ testForEachKey(Object v) {
+ keys[index++] = v;
+ }
+
+ final keysInOrder = const ["a", "b", "c", "d", "e"];
+ final valuesInOrder = const [1, 2, 3, 4, 5];
+
+ clear();
+ map.forEach(testForEachMap);
+ verifyKeys(keysInOrder);
+ verifyValues(valuesInOrder);
+
+ clear();
+ map.keys.forEach(testForEachKey);
+ verifyKeys(keysInOrder);
+
+ clear();
+ map.values.forEach(testForEachValue);
+ verifyValues(valuesInOrder);
+
+ // Remove and then insert.
+ map.remove("b");
+ map["b"] = 6;
+ final keysAfterBMove = const ["a", "c", "d", "e", "b"];
+ final valuesAfterBMove = const [1, 3, 4, 5, 6];
+
+
+ clear();
+ map.forEach(testForEachMap);
+ verifyKeys(keysAfterBMove);
+ verifyValues(valuesAfterBMove);
+
+ clear();
+ map.keys.forEach(testForEachKey);
+ verifyKeys(keysAfterBMove);
+
+ clear();
+ map.values.forEach(testForEachValue);
+ verifyValues(valuesAfterBMove);
+
+ // Update.
+ map["a"] = 0;
+ final valuesAfterAUpdate = const [0, 3, 4, 5, 6];
+
+ clear();
+ map.forEach(testForEachMap);
+ verifyKeys(keysAfterBMove);
+ verifyValues(valuesAfterAUpdate);
+
+ clear();
+ map.keys.forEach(testForEachKey);
+ verifyKeys(keysAfterBMove);
+
+ clear();
+ map.values.forEach(testForEachValue);
+ verifyValues(valuesAfterAUpdate);
+ }
+}
+
+main() {
+ LinkedHashMapTest.testMain();
+}
« 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