Skip to content

Commit

Permalink
test: Adds composite unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
NeedleInAJayStack committed May 26, 2024
1 parent c63265c commit 173f8a7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Tests/UnitsTests/MeasurementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,41 @@ final class MeasurementTests: XCTestCase {
)
}

func testCompositeUnitDefine() throws {
let ampereHour = Unit.ampere * .hour

// Test conversion from custom unit
XCTAssertEqual(
try 1.measured(in: ampereHour).convert(to: .coulomb),
3600.measured(in: .coulomb),
accuracy: accuracy
)

// Test conversion to custom unit
XCTAssertEqual(
try 3600.measured(in: .coulomb).convert(to: ampereHour),
1.measured(in: ampereHour),
accuracy: accuracy
)

let ampereSquareMeters = Unit.ampere * .meter.pow(2)
let joulePerTesla = Unit.joule / .tesla

// Test complex conversion from custom unit
XCTAssertEqual(
try 1.measured(in: ampereSquareMeters).convert(to: joulePerTesla),
1.measured(in: joulePerTesla),
accuracy: accuracy
)

// Test complex conversion to custom unit
XCTAssertEqual(
try 1.measured(in: joulePerTesla).convert(to: ampereSquareMeters),
1.measured(in: ampereSquareMeters),
accuracy: accuracy
)
}

func testUnitRegister() throws {
try Unit.register(
name: "centiinch",
Expand Down

0 comments on commit 173f8a7

Please sign in to comment.