@@ -1017,6 +1017,41 @@ end
10171017 end
10181018end
10191019
1020+ @testset " ustrip with unit conversion" begin
1021+ # Test Dimension/Dimension conversions
1022+ # Basic
1023+ @test ustrip (u " km" , 1000 u " m" ) == 1.0
1024+ @test ustrip (u " mm" , 1000 u " m" ) == 1000000.0
1025+ @test ustrip (u " s" , 1 u " minute" ) == 60.0
1026+ @test ustrip (u " minute" , 60 u " s" ) == 1.0
1027+
1028+ # Arrays
1029+ m_qarray = QuantityArray ([1000.0 , 2000.0 ], u " m" )
1030+ @test ustrip (u " km" , m_qarray) == [1.0 , 2.0 ]
1031+ @test ustrip (u " mm" , m_qarray) == [1000000.0 , 2000000.0 ]
1032+
1033+ # Mixed dimensions
1034+ @test_throws DimensionError ustrip (u " m" , u " K" )
1035+ @test_throws DimensionError ustrip (u " K" , u " m" )
1036+ @test_throws DimensionError ustrip (u " K" , u " m" )
1037+
1038+ # Test with SymbolicDimensions
1039+ @test ustrip (u " km" , us " m" ) == 0.001
1040+ @test ustrip (us " km" , u " m" ) == 0.001
1041+ @test ustrip (us " mm" , u " km" ) == 1000000.0
1042+ @test ustrip (us " km" , 500 us " km" ) == 500.0
1043+
1044+ # But, if no promotion, we still check dimensions symbolically!
1045+ @test_throws DimensionError ustrip (us " km" , us " m" )
1046+ @test_throws DimensionError ustrip (us " km" , us " m" )
1047+
1048+ # SymbolicDimensions arrays
1049+ m_sym_qarray = QuantityArray ([1000 us " km" , 2000 us " km" ])
1050+ @test ustrip (u " m" , m_sym_qarray) == [1000000.0 , 2000000.0 ]
1051+ @test ustrip (us " km" , m_sym_qarray) == [1000.0 , 2000.0 ]
1052+ @test_throws DimensionError ustrip (us " cm" , m_sym_qarray)
1053+ end
1054+
10201055@testset " Test missing" begin
10211056 x = 1.0 u " m"
10221057 @test round (Union{Int32,Missing}, FixedRational {Int32,100} (1 )) isa Int32
@@ -2054,6 +2089,15 @@ end
20542089 @test sprint (show, °C) == " °C"
20552090
20562091 @test sprint (show, °F) == " °F"
2092+
2093+ # Test the two-argument ustrip method with AffineUnit
2094+ @test ustrip (ua " degC" , 273.15 u " K" ) ≈ 0.0
2095+ @test ustrip (ua " degC" , 300.15 u " K" ) ≈ 27.0
2096+ @test ustrip (ua " degF" , 273.15 u " K" ) ≈ 32.0
2097+ @test ustrip (ua " degF" , 300.15 u " K" ) ≈ 80.6
2098+ @test ustrip (ua " degC" , 22 ua " degC" ) ≈ 22.0
2099+ @test ustrip (ua " degF" , 22 ua " degC" ) ≈ 71.6
2100+ @test_throws DimensionError ustrip (ua " degC" , 1.0 u " m" )
20572101end
20582102
20592103@testset " Test div" begin
0 commit comments