Skip to content

Document the recommended pattern for performing floating point equality-with-accuracy expectations, analogous to XCTAssertEqual(_:_:accuracy:) #165

@Kyle-Ye

Description

@Kyle-Ye

Description

What's the equivalents for XCTAssertEqual with accuracy in swift-testing

I do not find a Standard Library function to compare 2 Double with accuracy.

And the simplest way is we define one on client side. But I think this is a very common use case. Testing framework should support it out of box

Expected behavior

Support it directly in Testing framework the same as XCTest

Actual behavior

Write a compare(_ a: Double, _ b: Double, accuracy: Double) -> Bool by hand, and use #expect(compare(a, b, accuracy: accuracy))

Or

#expect(abs(a-b) <= accuracy)

Other consideration

Keeps using #expect(abs(a-b) <= accuracy) and add best practice suggestion to Migration documentation.

Steps to reproduce

No response

swift-testing version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation📚 Improvements or additions to documentationgood first issue🔰 Good for newcomerspublic-apiAffects public API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions