Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

How to test equality with a tolerance in Swift Testing

So I can see from the documentation that XCTAssertEqual(x, y) becomes #expect(x == y), but what about XCTAssertEqual(x, y, accuracy: 0.2)?

Does something already exist or do we need to write a more involved statement to see if x is less than y plus z and more than y minus z?

According to Github, the best way is to use isApproximatelyEqual(_:absoluteTolerance:) from the package swift-numerics:

#expect(someFloatingPointNumber.isApproximatelyEqual(0, absoluteTolerance: 0.001))
How to test equality with a tolerance in Swift Testing
 
 
Q