| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 testLength(2, set); | 401 testLength(2, set); |
| 402 Expect.isTrue(set.contains(e1)); | 402 Expect.isTrue(set.contains(e1)); |
| 403 Expect.isTrue(set.contains(e2)); | 403 Expect.isTrue(set.contains(e2)); |
| 404 | 404 |
| 405 var set2 = set.toSet(); | 405 var set2 = set.toSet(); |
| 406 testLength(2, set2); | 406 testLength(2, set2); |
| 407 Expect.isTrue(set2.contains(e1)); | 407 Expect.isTrue(set2.contains(e1)); |
| 408 Expect.isTrue(set2.contains(e2)); | 408 Expect.isTrue(set2.contains(e2)); |
| 409 } | 409 } |
| 410 | 410 |
| 411 void testIntSetFrom(setFrom) { |
| 412 List<num> numList = [2, 3, 5, 7, 11, 13]; |
| 413 |
| 414 Set<int> set1 = setFrom(numList); |
| 415 Expect.listEquals(numList, set1.toList()..sort()); |
| 416 |
| 417 Set<num> numSet = numList.toSet(); |
| 418 Set<int> set2 = setFrom(numSet); |
| 419 Expect.listEquals(numList, set2.toList()..sort()); |
| 420 |
| 421 Iterable<num> numIter = numList.where((x) => true); |
| 422 Set<int> set3 = setFrom(numIter); |
| 423 Expect.listEquals(numList, set3.toList()..sort()); |
| 424 |
| 425 Set<int> set4 = setFrom(new Iterable.generate(0)); |
| 426 Expect.isTrue(set4.isEmpty); |
| 427 } |
| 428 |
| 429 void testCESetFrom(setFrom) { |
| 430 List<Object> ceList = [new CE(2), new CE(3), new CE(5), |
| 431 new CE(7), new CE(11), new CE(13)]; |
| 432 |
| 433 Set<CE> set1 = setFrom(ceList); |
| 434 Expect.listEquals(ceList, set1.toList()..sort()); |
| 435 |
| 436 Set<ce> ceSet = ceList.toSet(); |
| 437 Set<CE> set2 = setFrom(ceSet); |
| 438 Expect.listEquals(ceList, set2.toList()..sort()); |
| 439 |
| 440 Iterable<ce> ceIter = ceList.where((x) => true); |
| 441 Set<CE> set3 = setFrom(ceIter); |
| 442 Expect.listEquals(ceList, set3.toList()..sort()); |
| 443 |
| 444 Set<CE> set4 = setFrom(new Iterable.generate(0)); |
| 445 Expect.isTrue(set4.isEmpty); |
| 446 } |
| 447 |
| 411 main() { | 448 main() { |
| 412 testMain(() => new HashSet()); | 449 testMain(() => new HashSet()); |
| 413 testMain(() => new LinkedHashSet()); | 450 testMain(() => new LinkedHashSet()); |
| 414 testMain(() => new HashSet.identity()); | 451 testMain(() => new HashSet.identity()); |
| 415 testMain(() => new LinkedHashSet.identity()); | 452 testMain(() => new LinkedHashSet.identity()); |
| 416 testMain(() => new HashSet(equals: identical)); | 453 testMain(() => new HashSet(equals: identical)); |
| 417 testMain(() => new LinkedHashSet(equals: identical)); | 454 testMain(() => new LinkedHashSet(equals: identical)); |
| 418 testMain(() => new HashSet(equals: (a, b) => a == b, | 455 testMain(() => new HashSet(equals: (a, b) => a == b, |
| 419 hashCode: (a) => -a.hashCode, | 456 hashCode: (a) => -a.hashCode, |
| 420 isValidKey: (a) => true)); | 457 isValidKey: (a) => true)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 450 testRetainWhere(([equals, hashCode, validKey, comparator]) => | 487 testRetainWhere(([equals, hashCode, validKey, comparator]) => |
| 451 new SplayTreeSet(comparator, validKey)); | 488 new SplayTreeSet(comparator, validKey)); |
| 452 | 489 |
| 453 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => | 490 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => |
| 454 new HashSet(equals: equals, hashCode: hashCode, isValidKey: validKey)); | 491 new HashSet(equals: equals, hashCode: hashCode, isValidKey: validKey)); |
| 455 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => | 492 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => |
| 456 new LinkedHashSet(equals: equals, hashCode: hashCode, | 493 new LinkedHashSet(equals: equals, hashCode: hashCode, |
| 457 isValidKey: validKey)); | 494 isValidKey: validKey)); |
| 458 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => | 495 testDifferenceIntersection(([equals, hashCode, validKey, comparator]) => |
| 459 new SplayTreeSet(comparator, validKey)); | 496 new SplayTreeSet(comparator, validKey)); |
| 497 |
| 498 testIntSetFrom((x) => new Set<int>.from(x)); |
| 499 testIntSetFrom((x) => new HashSet<int>.from(x)); |
| 500 testIntSetFrom((x) => new LinkedHashSet<int>.from(x)); |
| 501 testIntSetFrom((x) => new SplayTreeSet<int>.from(x)); |
| 502 |
| 503 testCESetFrom((x) => new Set<CE>.from(x)); |
| 504 testCESetFrom((x) => new HashSet<CE>.from(x)); |
| 505 testCESetFrom((x) => new LinkedHashSet<CE>.from(x)); |
| 506 testCESetFrom((x) => new SplayTreeSet<CE>.from(x)); |
| 507 |
| 508 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, |
| 509 customCompare(20), validKey)); |
| 510 testCESetFrom((x) => new SplayTreeSet<CE>.from(x, identityCompare)); |
| 460 } | 511 } |
| OLD | NEW |