mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: protocol extensions: de-underscore elementsEqual
Swift SVN r28234
This commit is contained in:
@@ -1892,7 +1892,7 @@ public func expectEqualSequence<
|
||||
file: String = __FILE__, line: UWord = __LINE__,
|
||||
collectMoreInfo: (()->String)? = nil
|
||||
) {
|
||||
if !equal(expected, actual, sameValue) {
|
||||
if !expected.elementsEqual(actual, isEquivalent: sameValue) {
|
||||
_anyExpectFailed = true
|
||||
println("check failed at \(file), line \(line)")
|
||||
_printStackTrace(stackTrace)
|
||||
@@ -2079,7 +2079,7 @@ public func expectEqualUnicodeScalars(
|
||||
collectMoreInfo: (()->String)? = nil
|
||||
) {
|
||||
let actualUnicodeScalars = _UnitTestArray(lazy(actual.unicodeScalars).map { $0.value })
|
||||
if !equal(expected, actualUnicodeScalars) {
|
||||
if !expected.elementsEqual(actualUnicodeScalars) {
|
||||
_anyExpectFailed = true
|
||||
println("check failed at \(file), line \(line)")
|
||||
_printStackTrace(stackTrace)
|
||||
|
||||
@@ -269,6 +269,7 @@ public func enumerate<Seq : SequenceType>(
|
||||
|
||||
/// Return `true` iff `a1` and `a2` contain the same elements in the
|
||||
/// same order.
|
||||
@availability(*, unavailable, message="call the 'equal()' method on the sequence")
|
||||
public func equal<
|
||||
S1 : SequenceType, S2 : SequenceType
|
||||
where
|
||||
@@ -276,12 +277,13 @@ public func equal<
|
||||
S1.Generator.Element : Equatable
|
||||
>(a1: S1, _ a2: S2) -> Bool {
|
||||
// FIXME(prext): remove this function when protocol extensions land.
|
||||
return a1._prext_elementsEqual(a2)
|
||||
return a1.elementsEqual(a2)
|
||||
}
|
||||
|
||||
/// Return true iff `a1` and `a2` contain equivalent elements, using
|
||||
/// `isEquivalent` as the equivalence test. Requires: `isEquivalent`
|
||||
/// is an [equivalence relation](http://en.wikipedia.org/wiki/Equivalence_relation)
|
||||
@availability(*, unavailable, message="call the 'equal()' method on the sequence")
|
||||
public func equal<
|
||||
S1 : SequenceType, S2 : SequenceType
|
||||
where
|
||||
@@ -290,7 +292,7 @@ public func equal<
|
||||
@noescape _ isEquivalent: (S1.Generator.Element, S1.Generator.Element) -> Bool)
|
||||
-> Bool {
|
||||
// FIXME(prext): remove this function when protocol extensions land.
|
||||
return a1._prext_elementsEqual(a2, isEquivalent: isEquivalent)
|
||||
return a1.elementsEqual(a2, isEquivalent: isEquivalent)
|
||||
}
|
||||
|
||||
/// Return true iff a1 precedes a2 in a lexicographical ("dictionary")
|
||||
|
||||
@@ -177,7 +177,7 @@ else:
|
||||
}%
|
||||
|
||||
${comment}
|
||||
final public func _prext_elementsEqual<
|
||||
final public func elementsEqual<
|
||||
OtherSequence : SequenceType where OtherSequence.${GElement} == ${GElement}
|
||||
>(
|
||||
other: OtherSequence${"," if preds else ""}
|
||||
|
||||
@@ -94,29 +94,6 @@ let startsWithTests = [
|
||||
StartsWithTest(false, [ 1, 2, 10 ], [ 1, 2, 3, 4, 10 ], [], [ 4, 10 ]),
|
||||
]
|
||||
|
||||
Algorithm.test("equal") {
|
||||
// FIXME(prext): remove these tests together with the equal() function when
|
||||
// protocol extensions land. These tests have been migrated to the new API.
|
||||
|
||||
var _0_4 = [0, 1, 2, 3]
|
||||
expectFalse(equal(_0_4, 0..<3))
|
||||
expectTrue(equal(_0_4, 0..<4))
|
||||
expectFalse(equal(_0_4, 0..<5))
|
||||
expectFalse(equal(_0_4, 1..<4))
|
||||
}
|
||||
|
||||
Algorithm.test("equal/predicate") {
|
||||
func compare(lhs: (Int, Int), _ rhs: (Int, Int)) -> Bool {
|
||||
return lhs.0 == rhs.0 && lhs.1 == rhs.1
|
||||
}
|
||||
|
||||
var _0_4 = [(0, 10), (1, 11), (2, 12), (3, 13)]
|
||||
expectFalse(equal(_0_4, [(0, 10), (1, 11), (2, 12)], compare))
|
||||
expectTrue(equal(_0_4, [(0, 10), (1, 11), (2, 12), (3, 13)], compare))
|
||||
expectFalse(equal(_0_4, [(0, 10), (1, 11), (2, 12), (3, 13), (4, 14)], compare))
|
||||
expectFalse(equal(_0_4, [(1, 11), (2, 12), (3, 13)], compare))
|
||||
}
|
||||
|
||||
Algorithm.test("contains") {
|
||||
// FIXME(prext): remove these tests together with the contains() function when
|
||||
// protocol extensions land. These tests have been migrated to the new API.
|
||||
@@ -828,7 +805,7 @@ SequenceTypeAlgorithms.test("elementsEqual/WhereElementIsEquatable") {
|
||||
test.other.map { MinimalEquatableValue($0) })
|
||||
expectEqual(
|
||||
test.expected,
|
||||
s._prext_elementsEqual(other),
|
||||
s.elementsEqual(other),
|
||||
stackTrace: test.loc.withCurrentLoc())
|
||||
expectEqual(
|
||||
test.expectedLeftoverSequence, s._prext_map { $0.value },
|
||||
@@ -846,7 +823,7 @@ SequenceTypeAlgorithms.test("elementsEqual/WhereElementIsEquatable") {
|
||||
test.other.map { MinimalEquatableValue($0) })
|
||||
expectEqual(
|
||||
test.expected,
|
||||
s._prext_elementsEqual(other),
|
||||
s.elementsEqual(other),
|
||||
stackTrace: test.loc.withCurrentLoc())
|
||||
expectEqual(
|
||||
test.sequence, s._prext_map { $0.value },
|
||||
@@ -867,7 +844,7 @@ SequenceTypeAlgorithms.test("elementsEqual/Predicate") {
|
||||
test.other.map { OpaqueValue($0) })
|
||||
expectEqual(
|
||||
test.expected,
|
||||
s._prext_elementsEqual(other) { $0.value == $1.value },
|
||||
s.elementsEqual(other) { $0.value == $1.value },
|
||||
stackTrace: test.loc.withCurrentLoc())
|
||||
expectEqual(
|
||||
test.expectedLeftoverSequence, s._prext_map { $0.value },
|
||||
@@ -885,7 +862,7 @@ SequenceTypeAlgorithms.test("elementsEqual/Predicate") {
|
||||
test.other.map { OpaqueValue($0) })
|
||||
expectEqual(
|
||||
test.expected,
|
||||
s._prext_elementsEqual(other) { $0.value == $1.value },
|
||||
s.elementsEqual(other) { $0.value == $1.value },
|
||||
stackTrace: test.loc.withCurrentLoc())
|
||||
expectEqual(
|
||||
test.sequence, s._prext_map { $0.value },
|
||||
|
||||
@@ -47,14 +47,14 @@ func equalsUnordered<T : Comparable>(
|
||||
func comparePair(lhs: (T, T), _ rhs: (T, T)) -> Bool {
|
||||
return lexicographicalCompare([ lhs.0, lhs.1 ], [ rhs.0, rhs.1 ])
|
||||
}
|
||||
return equal(sorted(lhs, comparePair), sorted(rhs, comparePair)) {
|
||||
return sorted(lhs, comparePair).elementsEqual(sorted(rhs, comparePair)) {
|
||||
(lhs: (T, T), rhs: (T, T)) -> Bool in
|
||||
lhs.0 == rhs.0 && lhs.1 == rhs.1
|
||||
}
|
||||
}
|
||||
|
||||
func equalsUnordered<T : Comparable>(lhs: [T], _ rhs: [T]) -> Bool {
|
||||
return equal(sorted(lhs), sorted(rhs))
|
||||
return sorted(lhs).elementsEqual(sorted(rhs))
|
||||
}
|
||||
|
||||
var _keyCount = _stdlib_AtomicInt(0)
|
||||
@@ -785,7 +785,7 @@ func _equalsWithoutElementIdentity(
|
||||
return list.map { ExpectedArrayElement(value: $0.value) }
|
||||
}
|
||||
|
||||
return equal(stripIdentity(lhs), stripIdentity(rhs))
|
||||
return stripIdentity(lhs).elementsEqual(stripIdentity(rhs))
|
||||
}
|
||||
|
||||
func _makeExpectedArrayContents(
|
||||
|
||||
@@ -405,7 +405,7 @@ NSStringAPIs.test("dataUsingEncoding(_:allowLossyConversion:)") {
|
||||
let expectedBytes: [UInt8] = [
|
||||
0xe3, 0x81, 0x82, 0xe3, 0x81, 0x84, 0xe3, 0x81, 0x86
|
||||
]
|
||||
expectTrue(equal(expectedBytes, bytes))
|
||||
expectEqualSequence(expectedBytes, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
|
||||
options: NSStringEncodingConversionOptions(0),
|
||||
range: startIndex..<endIndex, remainingRange: &remainingRange)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
expectEqual(11, usedLength)
|
||||
expectEqual(remainingRange.startIndex, advance(startIndex, 8))
|
||||
expectEqual(remainingRange.endIndex, endIndex)
|
||||
@@ -555,7 +555,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
|
||||
options: NSStringEncodingConversionOptions(0),
|
||||
range: startIndex..<endIndex, remainingRange: &remainingRange)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
expectEqual(4, usedLength)
|
||||
expectEqual(remainingRange.startIndex, advance(startIndex, 4))
|
||||
expectEqual(remainingRange.endIndex, endIndex)
|
||||
@@ -575,7 +575,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
|
||||
options: NSStringEncodingConversionOptions(0),
|
||||
range: startIndex..<endIndex, remainingRange: &remainingRange)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
expectEqual(19, usedLength)
|
||||
expectEqual(remainingRange.startIndex, endIndex)
|
||||
expectEqual(remainingRange.endIndex, endIndex)
|
||||
@@ -595,7 +595,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
|
||||
options: NSStringEncodingConversionOptions(0),
|
||||
range: startIndex..<endIndex, remainingRange: &remainingRange)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
expectEqual(4, usedLength)
|
||||
expectEqual(remainingRange.startIndex, advance(startIndex, 4))
|
||||
expectEqual(remainingRange.endIndex, endIndex)
|
||||
@@ -625,7 +625,7 @@ NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
|
||||
let result = s.getCString(&buffer, maxLength: 100,
|
||||
encoding: NSUTF8StringEncoding)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
}
|
||||
if true {
|
||||
// Limit buffer size with 'maxLength'.
|
||||
@@ -674,7 +674,7 @@ NSStringAPIs.test("getFileSystemRepresentation(_:maxLength:)") {
|
||||
let result = s.getFileSystemRepresentation(
|
||||
&buffer, maxLength: bufferLength)
|
||||
expectTrue(result)
|
||||
expectTrue(equal(expectedStr, buffer))
|
||||
expectEqualSequence(expectedStr, buffer)
|
||||
}
|
||||
if true {
|
||||
// Limit buffer size with 'maxLength'.
|
||||
|
||||
@@ -101,7 +101,7 @@ func checkEqual<
|
||||
S1.Generator.Element == S2.Generator.Element,
|
||||
S1.Generator.Element : Equatable
|
||||
>(a1: S1, _ a2: S2, _ expected: Bool) {
|
||||
if equal(a1, a2) != expected {
|
||||
if a1.elementsEqual(a2) != expected {
|
||||
let un = expected ? "un" : ""
|
||||
println("unexpectedly \(un)equal sequences!")
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ var RangeTestSuite = TestSuite("Range")
|
||||
RangeTestSuite.test("ReverseRange") {
|
||||
// We no longer have a ReverseRange, but we can still make sure that
|
||||
// lazy reversal works correctly.
|
||||
expectTrue(equal(lazy(0..<10).reverse(), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]))
|
||||
expectEqualSequence(lazy(0..<10).reverse(), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
|
||||
}
|
||||
|
||||
func isEquatable<E : Equatable>(e: E) {}
|
||||
|
||||
@@ -30,7 +30,7 @@ let eager: Array = reverse(lazy(2..<8).map { $0 * 3 })
|
||||
|
||||
// Make sure it has the right contents
|
||||
// CHECK-NEXT: true
|
||||
println(equal(eager, r))
|
||||
println(eager.elementsEqual(r))
|
||||
|
||||
let raboof = reduce(lazy("foobar").reverse(), "") {
|
||||
(s: String, c: Character) in s + String(c)
|
||||
|
||||
@@ -115,7 +115,7 @@ func isCocoaSet<T : Hashable>(s: Set<T>) -> Bool {
|
||||
}
|
||||
|
||||
func equalsUnordered(lhs: Set<Int>, _ rhs: Set<Int>) -> Bool {
|
||||
return equal(sorted(lhs), sorted(rhs)) {
|
||||
return sorted(lhs).elementsEqual(sorted(rhs)) {
|
||||
$0 == $1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user