mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: add a hook for dynamic dispatch in CollectionType.find()
This hook allows Set.find() to be equally efficient in static and generic contexts. This time, with correct tests. Swift SVN r27404
This commit is contained in:
@@ -3226,6 +3226,14 @@ SetTestSuite.test("first") {
|
||||
expectEmpty(emptySet.first)
|
||||
}
|
||||
|
||||
SetTestSuite.test("isEmpty") {
|
||||
let s1 = Set([1010, 2020, 3030])
|
||||
expectFalse(s1.isEmpty)
|
||||
|
||||
let emptySet = Set<Int>()
|
||||
expectTrue(emptySet.isEmpty)
|
||||
}
|
||||
|
||||
SetTestSuite.test("count") {
|
||||
let s1 = Set([1010, 2020, 3030])
|
||||
var s2 = Set([4040, 5050, 6060])
|
||||
@@ -3240,6 +3248,29 @@ SetTestSuite.test("contains") {
|
||||
expectFalse(Set<Int>().contains(1010))
|
||||
}
|
||||
|
||||
SetTestSuite.test("_customContainsEquatableElement") {
|
||||
let s1 = Set([1010, 2020, 3030, 4040, 5050, 6060])
|
||||
expectTrue(s1._customContainsEquatableElement(1010)!)
|
||||
expectFalse(s1._customContainsEquatableElement(999)!)
|
||||
expectFalse(Set<Int>()._customContainsEquatableElement(1010)!)
|
||||
}
|
||||
|
||||
SetTestSuite.test("indexOf") {
|
||||
let s1 = Set([1010, 2020, 3030, 4040, 5050, 6060])
|
||||
let foundIndex1 = s1.indexOf(1010)!
|
||||
expectEqual(1010, s1[foundIndex1])
|
||||
|
||||
expectEmpty(s1.indexOf(999))
|
||||
}
|
||||
|
||||
SetTestSuite.test("_customFindEquatableElement") {
|
||||
let s1 = Set([1010, 2020, 3030, 4040, 5050, 6060])
|
||||
let foundIndex1 = s1._customFindEquatableElement(1010)!!
|
||||
expectEqual(1010, s1[foundIndex1])
|
||||
|
||||
expectEmpty(s1._customFindEquatableElement(999)!)
|
||||
}
|
||||
|
||||
SetTestSuite.test("commutative") {
|
||||
let s1 = Set([1010, 2020, 3030])
|
||||
let s2 = Set([2020, 3030])
|
||||
|
||||
Reference in New Issue
Block a user