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 library map_test; | 5 library map_test; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 void main() { | 9 void main() { |
10 test(new HashMap()); | 10 test(new HashMap()); |
(...skipping 11 matching lines...) Expand all Loading... |
22 testWeirdStringKeys(new HashMap<String, String>()); | 22 testWeirdStringKeys(new HashMap<String, String>()); |
23 testWeirdStringKeys(new LinkedHashMap()); | 23 testWeirdStringKeys(new LinkedHashMap()); |
24 testWeirdStringKeys(new LinkedHashMap<String, String>()); | 24 testWeirdStringKeys(new LinkedHashMap<String, String>()); |
25 testWeirdStringKeys(new SplayTreeMap()); | 25 testWeirdStringKeys(new SplayTreeMap()); |
26 testWeirdStringKeys(new SplayTreeMap<String, String>()); | 26 testWeirdStringKeys(new SplayTreeMap<String, String>()); |
27 | 27 |
28 testNumericKeys(new Map()); | 28 testNumericKeys(new Map()); |
29 testNumericKeys(new Map<num, String>()); | 29 testNumericKeys(new Map<num, String>()); |
30 testNumericKeys(new HashMap()); | 30 testNumericKeys(new HashMap()); |
31 testNumericKeys(new HashMap<num, String>()); | 31 testNumericKeys(new HashMap<num, String>()); |
32 testNumericKeys(new HashMap(equals: identical)); | 32 testNumericKeys(new HashMap.identity()); |
33 testNumericKeys(new HashMap<num, String>(equals: identical)); | 33 testNumericKeys(new HashMap<num, String>.identity()); |
34 testNumericKeys(new LinkedHashMap()); | 34 testNumericKeys(new LinkedHashMap()); |
35 testNumericKeys(new LinkedHashMap<num, String>()); | 35 testNumericKeys(new LinkedHashMap<num, String>()); |
36 testNumericKeys(new LinkedHashMap(equals: identical)); | 36 testNumericKeys(new LinkedHashMap.identity()); |
37 testNumericKeys(new LinkedHashMap<num, String>(equals: identical)); | 37 testNumericKeys(new LinkedHashMap<num, String>.identity()); |
38 | 38 |
39 testNaNKeys(new Map()); | 39 testNaNKeys(new Map()); |
40 testNaNKeys(new Map<num, String>()); | 40 testNaNKeys(new Map<num, String>()); |
41 testNaNKeys(new HashMap()); | 41 testNaNKeys(new HashMap()); |
42 testNaNKeys(new HashMap<num, String>()); | 42 testNaNKeys(new HashMap<num, String>()); |
43 testNaNKeys(new LinkedHashMap()); | 43 testNaNKeys(new LinkedHashMap()); |
44 testNaNKeys(new LinkedHashMap<num, String>()); | 44 testNaNKeys(new LinkedHashMap<num, String>()); |
45 // Identity maps fail the NaN-keys tests because the test assumes that | 45 // Identity maps fail the NaN-keys tests because the test assumes that |
46 // NaN is not equal to NaN. | 46 // NaN is not equal to NaN. |
47 | 47 |
48 testIdentityMap(new HashMap(equals: identical)); | 48 testIdentityMap(new Map.identity()); |
49 testIdentityMap(new LinkedHashMap(equals: identical)); | 49 testIdentityMap(new HashMap.identity()); |
| 50 testIdentityMap(new LinkedHashMap.identity()); |
| 51 testIdentityMap(new HashMap(equals: identical, |
| 52 hashCode: Object.identityHashCode)); |
| 53 testIdentityMap(new LinkedHashMap(equals: identical, |
| 54 hashCode: Object.identityHashCode)); |
50 | 55 |
51 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode, | 56 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode, |
52 isValidKey: (v) => v is Customer)); | 57 isValidKey: (v) => v is Customer)); |
53 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode, | 58 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode, |
54 isValidKey: (v) => v is Customer)); | 59 isValidKey: (v) => v is Customer)); |
55 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals, | 60 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals, |
56 hashCode: myHashCode)); | 61 hashCode: myHashCode)); |
57 | 62 |
58 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals, | 63 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals, |
59 hashCode: myHashCode)); | 64 hashCode: myHashCode)); |
60 | 65 |
61 testIterationOrder(new LinkedHashMap()); | 66 testIterationOrder(new LinkedHashMap()); |
62 testIterationOrder(new LinkedHashMap(equals: identical)); | 67 testIterationOrder(new LinkedHashMap.identity()); |
63 | 68 |
64 testOtherKeys(new SplayTreeMap<int, int>()); | 69 testOtherKeys(new SplayTreeMap<int, int>()); |
65 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b, | 70 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b, |
66 (v) => v is int)); | 71 (v) => v is int)); |
67 testOtherKeys(new SplayTreeMap((int a, int b) => a - b, | 72 testOtherKeys(new SplayTreeMap((int a, int b) => a - b, |
68 (v) => v is int)); | 73 (v) => v is int)); |
69 testOtherKeys(new HashMap<int, int>()); | 74 testOtherKeys(new HashMap<int, int>()); |
70 testOtherKeys(new HashMap<int, int>(equals: identical)); | 75 testOtherKeys(new HashMap<int, int>.identity()); |
71 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode, | 76 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode, |
72 isValidKey: (v) => v is int)); | 77 isValidKey: (v) => v is int)); |
73 testOtherKeys(new HashMap(equals: (int x, int y) => x == y, | 78 testOtherKeys(new HashMap(equals: (int x, int y) => x == y, |
74 hashCode: (int v) => v.hashCode, | 79 hashCode: (int v) => v.hashCode, |
75 isValidKey: (v) => v is int)); | 80 isValidKey: (v) => v is int)); |
76 testOtherKeys(new LinkedHashMap<int, int>()); | 81 testOtherKeys(new LinkedHashMap<int, int>()); |
77 testOtherKeys(new LinkedHashMap<int, int>(equals: identical)); | 82 testOtherKeys(new LinkedHashMap<int, int>.identity()); |
78 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode, | 83 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode, |
79 isValidKey: (v) => v is int)); | 84 isValidKey: (v) => v is int)); |
80 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y, | 85 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y, |
81 hashCode: (int v) => v.hashCode, | 86 hashCode: (int v) => v.hashCode, |
82 isValidKey: (v) => v is int)); | 87 isValidKey: (v) => v is int)); |
83 } | 88 } |
84 | 89 |
85 | 90 |
86 void test(Map map) { | 91 void test(Map map) { |
87 testDeletedElement(map); | 92 testDeletedElement(map); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 map[0] = 0; | 711 map[0] = 0; |
707 map[1] = 1; | 712 map[1] = 1; |
708 map[2] = 2; | 713 map[2] = 2; |
709 Expect.isFalse(map.containsKey("not an int")); | 714 Expect.isFalse(map.containsKey("not an int")); |
710 Expect.isFalse(map.containsKey(1.5)); | 715 Expect.isFalse(map.containsKey(1.5)); |
711 Expect.isNull(map.remove("not an int")); | 716 Expect.isNull(map.remove("not an int")); |
712 Expect.isNull(map.remove(1.5)); | 717 Expect.isNull(map.remove(1.5)); |
713 Expect.isNull(map["not an int"]); | 718 Expect.isNull(map["not an int"]); |
714 Expect.isNull(map[1.5]); | 719 Expect.isNull(map[1.5]); |
715 } | 720 } |
OLD | NEW |