-
Notifications
You must be signed in to change notification settings - Fork 2
feature: Adds a unitless percent unit
#15
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,64 @@ final class MeasurementTests: XCTestCase { | |
| ) | ||
| } | ||
|
|
||
| func testPercent() throws { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an additional test in the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see that file?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops - my bad. I meant https://github.com/NeedleInAJayStack/Units/blob/main/Tests/UnitsTests/DefinitionTests.swift |
||
| XCTAssertEqual( | ||
| 1.measured(in: .percent), | ||
| 1.measured(in: .percent) | ||
| ) | ||
|
|
||
| XCTAssertNotEqual( | ||
| 100.measured(in: .percent), | ||
| 1.measured(in: .none) | ||
| ) | ||
|
|
||
| try { | ||
| let percent1 = 5.measured(in: .percent) | ||
| let percent2 = 5.measured(in: .percent) | ||
| XCTAssertEqual( | ||
| try percent1 + percent2, | ||
| 10.measured(in: .percent), | ||
| accuracy: accuracy | ||
| ) | ||
| }() | ||
|
|
||
| try { | ||
| let percent1 = 5.measured(in: .percent) | ||
| let value2 = 5.measured(in: .none) | ||
| XCTAssertThrowsError(try percent1 + value2) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, looks like this test is failing in CI because this no longer throws an error. I've added cross-unit addition/subtraction support since this MR was opened, so this will succeed and result in |
||
| }() | ||
|
|
||
| XCTAssertTrue( | ||
| 2.measured(in: .percent).isDimensionallyEquivalent( | ||
| to: 2.measured(in: .percent) | ||
| ) | ||
| ) | ||
|
|
||
| XCTAssertTrue( | ||
| 2.measured(in: .percent).isDimensionallyEquivalent( | ||
| to: 2.measured(in: .none) | ||
| ) | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| try 1.measured(in: .percent).convert(to: .none), | ||
| 0.01.measured(in: .none), | ||
| accuracy: accuracy | ||
| ) | ||
|
|
||
| XCTAssertEqual( | ||
| try 1.measured(in: .none).convert(to: .percent), | ||
| 100.measured(in: .percent), | ||
| accuracy: accuracy | ||
| ) | ||
|
|
||
| _ = { | ||
| let measurement = 1.measured(in: .percent) / 2.measured(in: .second) | ||
| XCTAssertEqual(measurement.unit, Unit.percent / Unit.second) | ||
| XCTAssertEqual(measurement.value, 0.5, accuracy: accuracy) | ||
| }() | ||
| } | ||
|
|
||
| func testComplexArithmetic() throws { | ||
| XCTAssertEqual( | ||
| try 1.measured(in: .mile / .mile) * 1.measured(in: .mile) - 1.measured(in: .mile), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.