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 positiveTest(); | 9 positiveTest(); |
10 emptyMapTest(); | 10 emptyMapTest(); |
(...skipping 25 matching lines...) Expand all Loading... |
36 Expect.isTrue(map is Map); | 36 Expect.isTrue(map is Map); |
37 Expect.isTrue(map is SplayTreeMap); | 37 Expect.isTrue(map is SplayTreeMap); |
38 Expect.isFalse(map is HashMap); | 38 Expect.isFalse(map is HashMap); |
39 | 39 |
40 Expect.equals(0, map.length); | 40 Expect.equals(0, map.length); |
41 Expect.equals(0, map.keys.length); | 41 Expect.equals(0, map.keys.length); |
42 Expect.equals(0, map.values.length); | 42 Expect.equals(0, map.values.length); |
43 } | 43 } |
44 | 44 |
45 void fewerValuesIterableTest() { | 45 void fewerValuesIterableTest() { |
46 Expect.throws(() => new SplayTreeMap.fromIterables([1,2], [0])); | 46 Expect.throws(() => new SplayTreeMap.fromIterables([1, 2], [0])); |
47 } | 47 } |
48 | 48 |
49 void fewerKeysIterableTest() { | 49 void fewerKeysIterableTest() { |
50 Expect.throws(() => new SplayTreeMap.fromIterables([1], [0,2])); | 50 Expect.throws(() => new SplayTreeMap.fromIterables([1], [0, 2])); |
51 } | 51 } |
52 | 52 |
53 void equalElementsTest() { | 53 void equalElementsTest() { |
54 var map = new SplayTreeMap.fromIterables([1, 2, 2], ["one", "two", "three"]); | 54 var map = new SplayTreeMap.fromIterables([1, 2, 2], ["one", "two", "three"]); |
55 | 55 |
56 Expect.isTrue(map is Map); | 56 Expect.isTrue(map is Map); |
57 Expect.isTrue(map is SplayTreeMap); | 57 Expect.isTrue(map is SplayTreeMap); |
58 Expect.isFalse(map is HashMap); | 58 Expect.isFalse(map is HashMap); |
59 | 59 |
60 Expect.equals(2, map.length); | 60 Expect.equals(2, map.length); |
61 Expect.equals(2, map.keys.length); | 61 Expect.equals(2, map.keys.length); |
62 Expect.equals(2, map.values.length); | 62 Expect.equals(2, map.values.length); |
63 | 63 |
64 Expect.equals("one", map[1]); | 64 Expect.equals("one", map[1]); |
65 Expect.equals("three", map[2]); | 65 Expect.equals("three", map[2]); |
66 } | 66 } |
67 | 67 |
68 | |
69 void genericTypeTest() { | 68 void genericTypeTest() { |
70 var map = new SplayTreeMap<int, String>.fromIterables( | 69 var map = new SplayTreeMap<int, String>.fromIterables( |
71 [1, 2, 3], ["one", "two", "three"]); | 70 [1, 2, 3], ["one", "two", "three"]); |
72 Expect.isTrue(map is Map<int, String>); | 71 Expect.isTrue(map is Map<int, String>); |
73 Expect.isTrue(map is SplayTreeMap<int, String>); | 72 Expect.isTrue(map is SplayTreeMap<int, String>); |
74 | 73 |
75 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. | 74 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. |
76 Expect.isFalse(map is SplayTreeMap<String, dynamic>); | 75 Expect.isFalse(map is SplayTreeMap<String, dynamic>); |
77 Expect.isFalse(map is SplayTreeMap<dynamic, int>); | 76 Expect.isFalse(map is SplayTreeMap<dynamic, int>); |
78 | 77 |
79 Expect.equals(3, map.length); | 78 Expect.equals(3, map.length); |
80 Expect.equals(3, map.keys.length); | 79 Expect.equals(3, map.keys.length); |
81 Expect.equals(3, map.values.length); | 80 Expect.equals(3, map.values.length); |
82 | 81 |
83 Expect.equals("one", map[1]); | 82 Expect.equals("one", map[1]); |
84 Expect.equals("two", map[2]); | 83 Expect.equals("two", map[2]); |
85 Expect.equals("three", map[3]); | 84 Expect.equals("three", map[3]); |
86 } | 85 } |
OLD | NEW |