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 set_test; | 5 library set_test; |
6 | 6 |
7 | 7 |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 import "dart:collection"; | 9 import "dart:collection"; |
10 | 10 |
11 void testMain(Set create()) { | 11 void testMain(Set create()) { |
12 Set set = create(); | 12 Set set = create(); |
| 13 |
13 testLength(0, set); | 14 testLength(0, set); |
14 set.add(1); | 15 set.add(1); |
15 testLength(1, set); | 16 testLength(1, set); |
16 Expect.isTrue(set.contains(1)); | 17 Expect.isTrue(set.contains(1)); |
17 | 18 |
18 set.add(1); | 19 set.add(1); |
19 testLength(1, set); | 20 testLength(1, set); |
20 Expect.isTrue(set.contains(1)); | 21 Expect.isTrue(set.contains(1)); |
21 | 22 |
22 set.remove(1); | 23 set.remove(1); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 testLength(1, set); | 183 testLength(1, set); |
183 } | 184 } |
184 | 185 |
185 void testLength(int length, Set set) { | 186 void testLength(int length, Set set) { |
186 Expect.equals(length, set.length); | 187 Expect.equals(length, set.length); |
187 (length == 0 ? Expect.isTrue : Expect.isFalse)(set.isEmpty); | 188 (length == 0 ? Expect.isTrue : Expect.isFalse)(set.isEmpty); |
188 (length != 0 ? Expect.isTrue : Expect.isFalse)(set.isNotEmpty); | 189 (length != 0 ? Expect.isTrue : Expect.isFalse)(set.isNotEmpty); |
189 } | 190 } |
190 | 191 |
191 main() { | 192 main() { |
192 testMain(() => new Set()); | |
193 testMain(() => new HashSet()); | 193 testMain(() => new HashSet()); |
| 194 testMain(() => new LinkedHashSet()); |
| 195 testMain(() => new HashSet(equals: identical)); |
| 196 testMain(() => new LinkedHashSet(equals: identical)); |
| 197 testMain(() => new HashSet(equals: (int a, int b) => a == b || a == -b, |
| 198 hashCode: (int n) => n.hashCode & (-n).hashCode, |
| 199 isValidKey: (n) => n is int)); |
| 200 testMain(() => new LinkedHashSet( |
| 201 equals: (int a, int b) => a == b || a == -b, |
| 202 hashCode: (int n) => n.hashCode & (-n).hashCode, |
| 203 isValidKey: (n) => n is int)); |
194 } | 204 } |
OLD | NEW |