When I run the following test case, I get XCTAssertEqual failed: ("nan") is not equal to ("nan")
error.
XCTAssertEqual(0.0 / 0.0, Double.nan)
How can I fix this error?
CodePudding user response:
As Joakim said, NaN
is never equal to any value, including itself.
You need to rewrite your code using isNaN
:
let someValue = 0.0 / 0.0
XCTAssertFalse(someValue.isNaN) // Will detect that someValue is a NaN