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:
Dmitri Hrybenko
2015-04-17 05:03:28 +00:00
parent e94b0f9b40
commit 02d254047b
5 changed files with 194 additions and 3 deletions

View File

@@ -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])