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

Side by Side Diff: tests/corelib/linked_hash_map_from_iterables_test.dart

Issue 22859069: Reapply "Make Map constructors return LinkedHashMap." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make map_values2_test know the order. Created 7 years, 3 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 main() { 8 main() {
9 positiveTest(); 9 positiveTest();
10 emptyMapTest(); 10 emptyMapTest();
11 fewerKeysIterableTest(); 11 fewerKeysIterableTest();
12 fewerValuesIterableTest(); 12 fewerValuesIterableTest();
13 equalElementsTest(); 13 equalElementsTest();
14 genericTypeTest(); 14 genericTypeTest();
15 } 15 }
16 16
17 void positiveTest() { 17 void positiveTest() {
18 var map = new LinkedHashMap.fromIterables([1, 2, 3], ["one", "two", "three"]); 18 var map = new LinkedHashMap.fromIterables([1, 2, 3], ["one", "two", "three"]);
19 Expect.isTrue(map is Map); 19 Expect.isTrue(map is Map);
20 Expect.isTrue(map is LinkedHashMap); 20 Expect.isTrue(map is LinkedHashMap);
21 Expect.isFalse(map is HashMap);
22 21
23 Expect.equals(3, map.length); 22 Expect.equals(3, map.length);
24 Expect.equals(3, map.keys.length); 23 Expect.equals(3, map.keys.length);
25 Expect.equals(3, map.values.length); 24 Expect.equals(3, map.values.length);
26 25
27 Expect.equals("one", map[1]); 26 Expect.equals("one", map[1]);
28 Expect.equals("two", map[2]); 27 Expect.equals("two", map[2]);
29 Expect.equals("three", map[3]); 28 Expect.equals("three", map[3]);
30 } 29 }
31 30
32 void emptyMapTest() { 31 void emptyMapTest() {
33 var map = new LinkedHashMap.fromIterables([], []); 32 var map = new LinkedHashMap.fromIterables([], []);
34 Expect.isTrue(map is Map); 33 Expect.isTrue(map is Map);
35 Expect.isTrue(map is LinkedHashMap); 34 Expect.isTrue(map is LinkedHashMap);
36 Expect.isFalse(map is HashMap);
37 35
38 Expect.equals(0, map.length); 36 Expect.equals(0, map.length);
39 Expect.equals(0, map.keys.length); 37 Expect.equals(0, map.keys.length);
40 Expect.equals(0, map.values.length); 38 Expect.equals(0, map.values.length);
41 } 39 }
42 40
43 void fewerValuesIterableTest() { 41 void fewerValuesIterableTest() {
44 Expect.throws(() => new LinkedHashMap.fromIterables([1,2], [0])); 42 Expect.throws(() => new LinkedHashMap.fromIterables([1,2], [0]));
45 } 43 }
46 44
47 void fewerKeysIterableTest() { 45 void fewerKeysIterableTest() {
48 Expect.throws(() => new LinkedHashMap.fromIterables([1], [0,2])); 46 Expect.throws(() => new LinkedHashMap.fromIterables([1], [0,2]));
49 } 47 }
50 48
51 void equalElementsTest() { 49 void equalElementsTest() {
52 var map = new LinkedHashMap.fromIterables([1, 2, 2], ["one", "two", "three"]); 50 var map = new LinkedHashMap.fromIterables([1, 2, 2], ["one", "two", "three"]);
53 Expect.isTrue(map is Map); 51 Expect.isTrue(map is Map);
54 Expect.isTrue(map is LinkedHashMap); 52 Expect.isTrue(map is LinkedHashMap);
55 Expect.isFalse(map is HashMap);
56 53
57 Expect.equals(2, map.length); 54 Expect.equals(2, map.length);
58 Expect.equals(2, map.keys.length); 55 Expect.equals(2, map.keys.length);
59 Expect.equals(2, map.values.length); 56 Expect.equals(2, map.values.length);
60 57
61 Expect.equals("one", map[1]); 58 Expect.equals("one", map[1]);
62 Expect.equals("three", map[2]); 59 Expect.equals("three", map[2]);
63 } 60 }
64 61
65 62
66 void genericTypeTest() { 63 void genericTypeTest() {
67 var map = new LinkedHashMap<int, String>.fromIterables( 64 var map = new LinkedHashMap<int, String>.fromIterables(
68 [1, 2, 3], ["one", "two", "three"]); 65 [1, 2, 3], ["one", "two", "three"]);
69 Expect.isTrue(map is Map<int, String>); 66 Expect.isTrue(map is Map<int, String>);
70 Expect.isTrue(map is LinkedHashMap<int, String>); 67 Expect.isTrue(map is LinkedHashMap<int, String>);
71 68
72 // Make sure it is not just LinkedHashMap<dynamic, dynamic>. 69 // Make sure it is not just LinkedHashMap<dynamic, dynamic>.
73 Expect.isFalse(map is LinkedHashMap<String, dynamic>); 70 Expect.isFalse(map is LinkedHashMap<String, dynamic>);
74 Expect.isFalse(map is LinkedHashMap<dynamic, int>); 71 Expect.isFalse(map is LinkedHashMap<dynamic, int>);
75 72
76 Expect.equals(3, map.length); 73 Expect.equals(3, map.length);
77 Expect.equals(3, map.keys.length); 74 Expect.equals(3, map.keys.length);
78 Expect.equals(3, map.values.length); 75 Expect.equals(3, map.values.length);
79 76
80 Expect.equals("one", map[1]); 77 Expect.equals("one", map[1]);
81 Expect.equals("two", map[2]); 78 Expect.equals("two", map[2]);
82 Expect.equals("three", map[3]); 79 Expect.equals("three", map[3]);
83 } 80 }
OLDNEW
« no previous file with comments | « tests/corelib/linked_hash_map_from_iterable_test.dart ('k') | tests/corelib/map_from_iterable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698