mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:48:25 +00:00
4d91dc7a47
Replacing usage of deprecated `new List()` and `new List(x)` in tests with `List.filled` or `[]` where applicable. Change-Id: Ie52a1869dfa25e141a8486c02c2d7668e9303ec9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141022 Reviewed-by: Riley Porter <rileyporter@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Riley Porter <rileyporter@google.com>
117 lines
2.7 KiB
Dart
117 lines
2.7 KiB
Dart
// 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?>.filled(5, null);
|
|
List<int?> values = new List<int?>.filled(5, null);
|
|
|
|
int index = 0;
|
|
|
|
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(dynamic key, dynamic value) {
|
|
Expect.equals(map[key], value);
|
|
keys[index] = key;
|
|
values[index] = value;
|
|
index++;
|
|
}
|
|
|
|
testForEachValue(dynamic v) {
|
|
values[index++] = v;
|
|
}
|
|
|
|
testForEachKey(dynamic 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();
|
|
}
|