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