OLD | NEW |
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 defaultFunctionValuesTest(); | 9 defaultFunctionValuesTest(); |
10 defaultKeyFunctionTest(); | 10 defaultKeyFunctionTest(); |
11 defaultValueFunctionTest(); | 11 defaultValueFunctionTest(); |
12 noDefaultValuesTest(); | 12 noDefaultValuesTest(); |
13 emptyIterableTest(); | 13 emptyIterableTest(); |
14 equalElementsTest(); | 14 equalElementsTest(); |
15 genericTypeTest(); | 15 genericTypeTest(); |
16 } | 16 } |
17 | 17 |
18 void defaultFunctionValuesTest() { | 18 void defaultFunctionValuesTest() { |
19 var map = new Map.fromIterable([1, 2, 3]); | 19 var map = new Map.fromIterable([1, 2, 3]); |
20 | 20 |
21 Expect.isTrue(map is Map); | 21 Expect.isTrue(map is Map); |
22 Expect.isTrue(map is LinkedHashMap); | 22 Expect.isTrue(map is HashMap); |
23 | 23 |
24 Expect.equals(3, map.length); | 24 Expect.equals(3, map.length); |
25 Expect.equals(3, map.keys.length); | 25 Expect.equals(3, map.keys.length); |
26 Expect.equals(3, map.values.length); | 26 Expect.equals(3, map.values.length); |
27 | 27 |
28 Expect.equals(1, map[1]); | 28 Expect.equals(1, map[1]); |
29 Expect.equals(2, map[2]); | 29 Expect.equals(2, map[2]); |
30 Expect.equals(3, map[3]); | 30 Expect.equals(3, map[3]); |
31 } | 31 } |
32 | 32 |
33 void defaultKeyFunctionTest() { | 33 void defaultKeyFunctionTest() { |
34 var map = new Map.fromIterable([1, 2, 3], value: (x) => x + 1); | 34 var map = new Map.fromIterable([1, 2, 3], value: (x) => x + 1); |
35 | 35 |
36 Expect.isTrue(map is Map); | 36 Expect.isTrue(map is Map); |
37 Expect.isTrue(map is LinkedHashMap); | 37 Expect.isTrue(map is HashMap); |
38 | 38 |
39 Expect.equals(3, map.length); | 39 Expect.equals(3, map.length); |
40 Expect.equals(3, map.keys.length); | 40 Expect.equals(3, map.keys.length); |
41 Expect.equals(3, map.values.length); | 41 Expect.equals(3, map.values.length); |
42 | 42 |
43 Expect.equals(2, map[1]); | 43 Expect.equals(2, map[1]); |
44 Expect.equals(3, map[2]); | 44 Expect.equals(3, map[2]); |
45 Expect.equals(4, map[3]); | 45 Expect.equals(4, map[3]); |
46 } | 46 } |
47 | 47 |
48 void defaultValueFunctionTest() { | 48 void defaultValueFunctionTest() { |
49 var map = new Map.fromIterable([1, 2, 3], key: (x) => x + 1); | 49 var map = new Map.fromIterable([1, 2, 3], key: (x) => x + 1); |
50 | 50 |
51 Expect.isTrue(map is Map); | 51 Expect.isTrue(map is Map); |
52 Expect.isTrue(map is LinkedHashMap); | 52 Expect.isTrue(map is HashMap); |
53 | 53 |
54 Expect.equals(3, map.length); | 54 Expect.equals(3, map.length); |
55 Expect.equals(3, map.keys.length); | 55 Expect.equals(3, map.keys.length); |
56 Expect.equals(3, map.values.length); | 56 Expect.equals(3, map.values.length); |
57 | 57 |
58 Expect.equals(1, map[2]); | 58 Expect.equals(1, map[2]); |
59 Expect.equals(2, map[3]); | 59 Expect.equals(2, map[3]); |
60 Expect.equals(3, map[4]); | 60 Expect.equals(3, map[4]); |
61 } | 61 } |
62 | 62 |
63 void noDefaultValuesTest() { | 63 void noDefaultValuesTest() { |
64 var map = new Map.fromIterable([1, 2, 3], | 64 var map = new Map.fromIterable([1, 2, 3], |
65 key: (x) => x + 1, value: (x) => x - 1); | 65 key: (x) => x + 1, value: (x) => x - 1); |
66 | 66 |
| 67 |
67 Expect.isTrue(map is Map); | 68 Expect.isTrue(map is Map); |
68 Expect.isTrue(map is LinkedHashMap); | 69 Expect.isTrue(map is HashMap); |
69 | 70 |
70 Expect.equals(3, map.length); | 71 Expect.equals(3, map.length); |
71 Expect.equals(3, map.keys.length); | 72 Expect.equals(3, map.keys.length); |
72 Expect.equals(3, map.values.length); | 73 Expect.equals(3, map.values.length); |
73 | 74 |
74 Expect.equals(0, map[2]); | 75 Expect.equals(0, map[2]); |
75 Expect.equals(1, map[3]); | 76 Expect.equals(1, map[3]); |
76 Expect.equals(2, map[4]); | 77 Expect.equals(2, map[4]); |
77 } | 78 } |
78 | 79 |
79 void emptyIterableTest() { | 80 void emptyIterableTest() { |
80 var map = new Map.fromIterable([]); | 81 var map = new Map.fromIterable([]); |
81 Expect.isTrue(map is Map); | 82 Expect.isTrue(map is Map); |
82 Expect.isTrue(map is LinkedHashMap); | 83 Expect.isTrue(map is HashMap); |
83 | 84 |
84 Expect.equals(0, map.length); | 85 Expect.equals(0, map.length); |
85 Expect.equals(0, map.keys.length); | 86 Expect.equals(0, map.keys.length); |
86 Expect.equals(0, map.values.length); | 87 Expect.equals(0, map.values.length); |
87 } | 88 } |
88 | 89 |
89 void equalElementsTest() { | 90 void equalElementsTest() { |
90 var map = new Map.fromIterable([1, 2, 2], key: (x) => x + 1); | 91 var map = new Map.fromIterable([1, 2, 2], key: (x) => x + 1); |
91 | 92 |
92 Expect.isTrue(map is Map); | 93 Expect.isTrue(map is Map); |
93 Expect.isTrue(map is LinkedHashMap); | 94 Expect.isTrue(map is HashMap); |
94 | 95 |
95 Expect.equals(2, map.length); | 96 Expect.equals(2, map.length); |
96 Expect.equals(2, map.keys.length); | 97 Expect.equals(2, map.keys.length); |
97 Expect.equals(2, map.values.length); | 98 Expect.equals(2, map.values.length); |
98 | 99 |
99 Expect.equals(1, map[2]); | 100 Expect.equals(1, map[2]); |
100 Expect.equals(2, map[3]); | 101 Expect.equals(2, map[3]); |
101 } | 102 } |
102 | 103 |
103 void genericTypeTest() { | 104 void genericTypeTest() { |
104 var map = new Map<int, String>.fromIterable([1, 2, 3], value: (x) => '$x'); | 105 var map = new Map<int, String>.fromIterable([1, 2, 3], value: (x) => '$x'); |
105 Expect.isTrue(map is Map<int, String>); | 106 Expect.isTrue(map is Map<int, String>); |
106 | 107 |
107 // Make sure it is not just Map<dynamic, dynamic>. | 108 // Make sure it is not just Map<dynamic, dynamic>. |
108 Expect.isFalse(map is Map<String, dynamic>); | 109 Expect.isFalse(map is Map<String, dynamic>); |
109 Expect.isFalse(map is Map<dynamic, int>); | 110 Expect.isFalse(map is Map<dynamic, int>); |
110 } | 111 } |
111 | 112 |
OLD | NEW |