File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -427,6 +427,41 @@ final class MeasurementTests: XCTestCase {
427427 )
428428 }
429429
430+ func testCompositeUnitDefine( ) throws {
431+ let ampereHour = Unit . ampere * . hour
432+
433+ // Test conversion from custom unit
434+ XCTAssertEqual (
435+ try 1 . measured ( in: ampereHour) . convert ( to: . coulomb) ,
436+ 3600 . measured ( in: . coulomb) ,
437+ accuracy: accuracy
438+ )
439+
440+ // Test conversion to custom unit
441+ XCTAssertEqual (
442+ try 3600 . measured ( in: . coulomb) . convert ( to: ampereHour) ,
443+ 1 . measured ( in: ampereHour) ,
444+ accuracy: accuracy
445+ )
446+
447+ let ampereSquareMeters = Unit . ampere * . meter. pow ( 2 )
448+ let joulePerTesla = Unit . joule / . tesla
449+
450+ // Test complex conversion from custom unit
451+ XCTAssertEqual (
452+ try 1 . measured ( in: ampereSquareMeters) . convert ( to: joulePerTesla) ,
453+ 1 . measured ( in: joulePerTesla) ,
454+ accuracy: accuracy
455+ )
456+
457+ // Test complex conversion to custom unit
458+ XCTAssertEqual (
459+ try 1 . measured ( in: joulePerTesla) . convert ( to: ampereSquareMeters) ,
460+ 1 . measured ( in: ampereSquareMeters) ,
461+ accuracy: accuracy
462+ )
463+ }
464+
430465 func testUnitRegister( ) throws {
431466 try Unit . register (
432467 name: " centiinch " ,
You can’t perform that action at this time.
0 commit comments