Skip to content

Commit bbba01e

Browse files
committed
test: 2-arg version of ustrip
1 parent 16defb0 commit bbba01e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/unittests.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,41 @@ end
10171017
end
10181018
end
10191019

1020+
@testset "ustrip with unit conversion" begin
1021+
# Test Dimension/Dimension conversions
1022+
# Basic
1023+
@test ustrip(u"km", 1000u"m") == 1.0
1024+
@test ustrip(u"mm", 1000u"m") == 1000000.0
1025+
@test ustrip(u"s", 1u"minute") == 60.0
1026+
@test ustrip(u"minute", 60u"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", 500us"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([1000us"km", 2000us"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.0u"m"
10221057
@test round(Union{Int32,Missing}, FixedRational{Int32,100}(1)) isa Int32

0 commit comments

Comments
 (0)