Skip to content

Commit ce4c98b

Browse files
committed
XCTAssertEqualWithAccuracy behavor does not match true XCTest.framework
The accuracy threshold check only works with unsigned numbers, however the distanceTo method we get from Strideable works in terms of offsets which can be negative. We need to take the absolute value of the distance. This issue was causing tests for swiftlang/swift-corelibs-foundation#37 to fail.
1 parent c865095 commit ce4c98b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

XCTest/XCTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public func XCTAssertEqual<T, U : Equatable>(@autoclosure expression1: () -> [T
177177
}
178178

179179
public func XCTAssertEqualWithAccuracy<T : FloatingPointType>(@autoclosure expression1: () -> T, @autoclosure _ expression2: () -> T, accuracy: T, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
180-
XCTAssert(expression1().distanceTo(expression2()) <= accuracy.distanceTo(T(0)), message, file: file, line: line)
180+
XCTAssert(abs(expression1().distanceTo(expression2())) <= abs(accuracy.distanceTo(T(0))), message, file: file, line: line)
181181
}
182182

183183
public func XCTAssertFalse(@autoclosure expression: () -> BooleanType, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
@@ -225,7 +225,7 @@ public func XCTAssertNotEqual<T, U : Equatable>(@autoclosure expression1: () ->
225225
}
226226

227227
public func XCTAssertNotEqualWithAccuracy<T : FloatingPointType>(@autoclosure expression1: () -> T, @autoclosure _ expression2: () -> T, _ accuracy: T, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
228-
XCTAssert(expression1().distanceTo(expression2()) > accuracy.distanceTo(T(0)), message, file: file, line: line)
228+
XCTAssert(abs(expression1().distanceTo(expression2())) > abs(accuracy.distanceTo(T(0))), message, file: file, line: line)
229229
}
230230

231231
public func XCTAssertNotNil(@autoclosure expression: () -> Any?, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {

0 commit comments

Comments
 (0)