-
Notifications
You must be signed in to change notification settings - Fork 114
Add documentation for numeric value comparison within specified accuracy #165 #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the appropriate location for this documentation. It should be included in the migration document.
@@ -355,6 +355,11 @@ their equivalents in the testing library: | |||
| `try XCTUnwrap(x)` | `try #require(x)` | | |||
| `XCTFail("…")` | `Issue.record("…")` | | |||
|
|||
- Note: When comparing two numeric values within a specified accuracy, i.e. the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@medreisbach @chuckdude Can you advise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the modifications suggested by @heckj look great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestions for slightly tighter and direct phrasing
@@ -355,6 +355,11 @@ their equivalents in the testing library: | |||
| `try XCTUnwrap(x)` | `try #require(x)` | | |||
| `XCTFail("…")` | `Issue.record("…")` | | |||
|
|||
- Note: When comparing two numeric values within a specified accuracy, i.e. the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Note: When comparing two numeric values within a specified accuracy, i.e. the | |
- Note: To check that two numeric values are equivalent within a specified accuracy, as in the |
@@ -355,6 +355,11 @@ their equivalents in the testing library: | |||
| `try XCTUnwrap(x)` | `try #require(x)` | | |||
| `XCTFail("…")` | `Issue.record("…")` | | |||
|
|||
- Note: When comparing two numeric values within a specified accuracy, i.e. the | |||
analogue of [`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal) | |||
, please import [the swift-numerics package](https://github.com/apple/swift-numerics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, please import [the swift-numerics package](https://github.com/apple/swift-numerics) | |
, import [the swift-numerics package](https://github.com/apple/swift-numerics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also reduce the link to just "swift-numerics" but that's not a hard rule, just my preference.
- Note: When comparing two numeric values within a specified accuracy, i.e. the | ||
analogue of [`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal) | ||
, please import [the swift-numerics package](https://github.com/apple/swift-numerics) | ||
and use the ``isApproximatelyEqual()`` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use the ``isApproximatelyEqual()`` function. | |
to use the ``isApproximatelyEqual()`` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would sound odd. Simplified: "to do x, do y to do z".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flip the whole ordering, which would make it more direct, something akin to:
"Import swift-numerics and use isApproximateEqual
to compare two numeric values to within an accuracy bound you specify. Use this technique as a replacement for XCTAssertEqual(::accuracy)."
or something akin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be confusing since it would introduce instructions to import swift-numerics without a reader knowing why that was important. State the problem before the solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you’re right. maybe lead with “swift-testing doesn’t include an exact duplicate of XCTAssertEqual(::accuracy)” and then jump into the direct advice.
- Note: To check that two numeric values are equivalent within a specified | ||
accuracy, as in the analogue of | ||
[`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal) | ||
, please import [swift-numerics](https://github.com/apple/swift-numerics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The comma needs to be on the same line as the link, otherwise it will be rendered with leading whitespace.
- Remove the word "please" as overly colloquial.
analogue of [`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal) | ||
, please import [the swift-numerics package](https://github.com/apple/swift-numerics) | ||
and use the ``isApproximatelyEqual()`` function. | ||
- Note: To check that two numeric values are equivalent within a specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Note: To check that two numeric values are equivalent within a specified | |
To check that two numeric values are equivalent within a specified |
The callout box is not necessary here.
accuracy, as in the analogue of | ||
[`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal) | ||
, please import [swift-numerics](https://github.com/apple/swift-numerics) | ||
to use the ``isApproximatelyEqual()`` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to use the ``isApproximatelyEqual()`` function. | |
and use the ``isApproximatelyEqual()`` function. |
I know @heckj suggested the opposite change, but "and" would be more grammatically correct in this position. (Sorry Joe!)
, please import [the swift-numerics package](https://github.com/apple/swift-numerics) | ||
and use the ``isApproximatelyEqual()`` function. | ||
- Note: To check that two numeric values are equivalent within a specified | ||
accuracy, as in the analogue of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chuckdude @medreisbach Does Apple style prefer "analogue" or "analog"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me places his bet on "analog" - the American english spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect you're right, hence why I asked! 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You both win!
It's "analog", see https://support.apple.com/guide/applestyleguide/a-apsg3acde405/web.
To check that two numeric values are equivalent within a specified | ||
accuracy, as in the analog of | ||
[`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal), | ||
import [swift-numerics](https://github.com/apple/swift-numerics) | ||
and use the ``isApproximatelyEqual()`` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grynspan @heckj What do you think about the following?
To check that two numeric values are equivalent within a specified | |
accuracy, as in the analog of | |
[`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal), | |
import [swift-numerics](https://github.com/apple/swift-numerics) | |
and use the ``isApproximatelyEqual()`` function. | |
The testing library doesn’t provide an equivalent of [`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal). To compare two numeric values within a specified accuracy, use ``isApproximatelyEqual()`` from [swift-numerics](https://github.com/apple/swift-numerics). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop "currently"—we're not planning to add an equivalent precisely because swift-numerics is the preferred solution. We don't anticipate a change here.
"an equivalent operation for" -> "an equivalent of"
"you can use" -> "use"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the recommended change to reflect Jonathan's feedback. I only suggested "you can use" instead of "use" because I wasn't sure how direct we wanted to be. If we feel this is the "preferred solution" then "use" works much better.
The testing library doesn’t provide an equivalent of | ||
[`XCTAssertEqual(_:_:accuracy:_:file:line:)`](https://developer.apple.com/documentation/xctest/3551607-xctassertequal). | ||
To compare two numeric values within a specified accuracy, | ||
use ``isApproximatelyEqual()`` from [swift-numerics](https://github.com/apple/swift-numerics). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ``isApproximatelyEqual()`` from [swift-numerics](https://github.com/apple/swift-numerics). | |
use `isApproximatelyEqual()` from [swift-numerics](https://github.com/apple/swift-numerics). |
(DocC uses double backticks to refer to symbols in the same package or project.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for adding this and making those changes.
Add documentation about how to compare two numeric values within specified accuracy.
Motivation:
Issue #165. swift-testing doesn't have an analog of XCAssertEquals of specified accuracy. There is no such function in the standard library. It's unclear to users how they can compare two numeric values.
Resolves #165.
Modifications:
Added a comment in the
#expect
macro: should useisApproximatelyEqual
in the swift-numerics.Result:
Clearer to users what numeric value comparison is.
Checklist: