| 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 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 Expect.listEquals(ceList, set2.toList()..sort()); | 438 Expect.listEquals(ceList, set2.toList()..sort()); |
| 439 | 439 |
| 440 Iterable<CE> ceIter = ceList.where((x) => true); | 440 Iterable<CE> ceIter = ceList.where((x) => true); |
| 441 Set<CE> set3 = setFrom(ceIter); | 441 Set<CE> set3 = setFrom(ceIter); |
| 442 Expect.listEquals(ceList, set3.toList()..sort()); | 442 Expect.listEquals(ceList, set3.toList()..sort()); |
| 443 | 443 |
| 444 Set<CE> set4 = setFrom(new Iterable.generate(0)); | 444 Set<CE> set4 = setFrom(new Iterable.generate(0)); |
| 445 Expect.isTrue(set4.isEmpty); | 445 Expect.isTrue(set4.isEmpty); |
| 446 } | 446 } |
| 447 | 447 |
| 448 class A {} |
| 449 class B {} |
| 450 class C implements A, B {} |
| 451 |
| 452 void testASetFrom(setFrom) { |
| 453 List<B> bList= <B>[new C()]; |
| 454 // Set.from allows to cast elements. |
| 455 Set<A> aSet = setFrom(bList); |
| 456 Expect.isTrue(aSet.length == 1); |
| 457 } |
| 458 |
| 448 main() { | 459 main() { |
| 449 testMain(() => new HashSet()); | 460 testMain(() => new HashSet()); |
| 450 testMain(() => new LinkedHashSet()); | 461 testMain(() => new LinkedHashSet()); |
| 451 testMain(() => new HashSet.identity()); | 462 testMain(() => new HashSet.identity()); |
| 452 testMain(() => new LinkedHashSet.identity()); | 463 testMain(() => new LinkedHashSet.identity()); |
| 453 testMain(() => new HashSet(equals: identical)); | 464 testMain(() => new HashSet(equals: identical)); |
| 454 testMain(() => new LinkedHashSet(equals: identical)); | 465 testMain(() => new LinkedHashSet(equals: identical)); |
| 455 testMain(() => new HashSet(equals: (a, b) => a == b, | 466 testMain(() => new HashSet(equals: (a, b) => a == b, |
| 456 hashCode: (a) => -a.hashCode, | 467 hashCode: (a) => -a.hashCode, |
| 457 isValidKey: (a) => true)); | 468 isValidKey: (a) => true)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 testIntSetFrom((x) => new SplayTreeSet<int>.from(x)); | 512 testIntSetFrom((x) => new SplayTreeSet<int>.from(x)); |
| 502 | 513 |
| 503 testCESetFrom((x) => new Set<CE>.from(x)); | 514 testCESetFrom((x) => new Set<CE>.from(x)); |
| 504 testCESetFrom((x) => new HashSet<CE>.from(x)); | 515 testCESetFrom((x) => new HashSet<CE>.from(x)); |
| 505 testCESetFrom((x) => new LinkedHashSet<CE>.from(x)); | 516 testCESetFrom((x) => new LinkedHashSet<CE>.from(x)); |
| 506 testCESetFrom((x) => new SplayTreeSet<CE>.from(x)); | 517 testCESetFrom((x) => new SplayTreeSet<CE>.from(x)); |
| 507 | 518 |
| 508 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, | 519 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, |
| 509 customCompare(20), validKey)); | 520 customCompare(20), validKey)); |
| 510 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); | 521 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); |
| 522 |
| 523 testASetFrom((x) => new Set<A>.from(x)); |
| 524 testASetFrom((x) => new HashSet<A>.from(x)); |
| 525 testASetFrom((x) => new LinkedHashSet<A>.from(x)); |
| 526 testASetFrom((x) => new SplayTreeSet<A>.from(x)); |
| 511 } | 527 } |
| OLD | NEW |