@@ -6,14 +6,23 @@ import SaferIntegers: SafeInt16
6
6
using Test
7
7
8
8
# Try to work with different preferred units:
9
- Unitful. preferunits (u " mA" )
10
9
Unitful. preferunits (u " km" )
11
10
11
+ risapprox (x:: Unitful.Quantity , y:: Unitful.Quantity ; kws... ) =
12
+ let (xfloat, yfloat) = (Unitful. ustrip ∘ Unitful. upreferred). ((x, y))
13
+ return isapprox (xfloat, yfloat; kws... )
14
+ end
15
+
16
+ factor_for_preferred_units = 1e-3
17
+
12
18
for T in [Float16, Float32, Float64], R in [Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
13
- x = DynamicQuantities. Quantity (T (0.2 ), R, length= 1 , amount= 2 , current= - 1 // 2 , luminosity= 2 // 5 )
14
- x_unitful = T (0.2 )u "km *mol^2*A^(-1//2)*cd^(2//5)"
19
+ x = DynamicQuantities. Quantity (T (0.2 * factor_for_preferred_units ), R, length= 1 , amount= 2 , current= - 1 // 2 , luminosity= 2 // 5 )
20
+ x_unitful = T (0.2 )u "m *mol^2*A^(-1//2)*cd^(2//5)"
15
21
16
- @test convert (Unitful. Quantity, x) ≈ x_unitful
22
+ @test risapprox ( convert (Unitful. Quantity, x), x_unitful; atol = 1e-6 )
17
23
@test typeof (convert (DynamicQuantities. Quantity, convert (Unitful. Quantity, x))) <: DynamicQuantities.Quantity{T,DynamicQuantities.DEFAULT_DIM_TYPE}
18
- @test convert (DynamicQuantities. Quantity{T,R}, convert (Unitful. Quantity, x)) ≈ x
24
+ @test isapprox (convert (DynamicQuantities. Quantity, convert (Unitful. Quantity, x)), x; atol= 1e-6 )
25
+
26
+ @test isapprox (convert (DynamicQuantities. Quantity{T,R}, x_unitful), x; atol= 1e-6 )
27
+ @test risapprox (convert (Unitful. Quantity, convert (DynamicQuantities. Quantity{T,R}, x_unitful)), Unitful. upreferred (x_unitful); atol= 1e-6 )
19
28
end
0 commit comments