@@ -11,9 +11,9 @@ using Test
11
11
12
12
@testset " Basic utilities" begin
13
13
14
- for T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
14
+ for Q in [Quantity, GenericQuantity], T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
15
15
D = Dimensions{R}
16
- x = Quantity (T (0.2 ), D, length= 1 , mass= 2.5 )
16
+ x = Q (T (0.2 ), D, length= 1 , mass= 2.5 )
17
17
18
18
@test typeof (x). parameters[1 ] == T
19
19
@test typeof (x). parameters[2 ] == D
@@ -22,7 +22,7 @@ using Test
22
22
@test ustrip (x) ≈ T (0.2 )
23
23
@test dimension (x) == Dimensions (R, length= 1 , mass= 5 // 2 )
24
24
if R == DEFAULT_DIM_TYPE
25
- @test x == Quantity (T (0.2 ), length= 1 , mass= 2.5 )
25
+ @test x == Q (T (0.2 ), length= 1 , mass= 2.5 )
26
26
@test dimension (x) == Dimensions (length= 1 , mass= 5 // 2 )
27
27
end
28
28
@@ -77,11 +77,11 @@ using Test
77
77
@test iszero (x. dimensions) == false
78
78
@test iszero (y. dimensions) == true
79
79
80
- y = Quantity (T (2 // 10 ), D, length= 1 , mass= 5 // 2 )
80
+ y = Q (T (2 // 10 ), D, length= 1 , mass= 5 // 2 )
81
81
82
82
@test y ≈ x
83
83
84
- y = Quantity (T (2 // 10 ), D, length= 1 , mass= 6 // 2 )
84
+ y = Q (T (2 // 10 ), D, length= 1 , mass= 6 // 2 )
85
85
86
86
@test ! (y ≈ x)
87
87
@@ -105,26 +105,26 @@ using Test
105
105
@test uamount (y) == R (0 )
106
106
@test ustrip (y) ≈ T (0.2 ^ 2.1 )
107
107
108
- dimensionless = Quantity (one (T), D)
108
+ dimensionless = Q (one (T), D)
109
109
y = T (2 ) + dimensionless
110
110
@test ustrip (y) == T (3 )
111
111
@test dimension (y) == Dimensions (R)
112
- @test typeof (y) == Quantity {T,D}
112
+ @test typeof (y) == Q {T,D}
113
113
114
114
y = T (2 ) - dimensionless
115
115
@test ustrip (y) == T (1 )
116
116
@test dimension (y) == Dimensions (R)
117
- @test typeof (y) == Quantity {T,D}
117
+ @test typeof (y) == Q {T,D}
118
118
119
119
y = dimensionless + T (2 )
120
120
@test ustrip (y) == T (3 )
121
121
y = dimensionless - T (2 )
122
122
@test ustrip (y) == T (- 1 )
123
123
124
- @test_throws DimensionError Quantity (one (T), D, length= 1 ) + 1.0
125
- @test_throws DimensionError Quantity (one (T), D, length= 1 ) - 1.0
126
- @test_throws DimensionError 1.0 + Quantity (one (T), D, length= 1 )
127
- @test_throws DimensionError 1.0 - Quantity (one (T), D, length= 1 )
124
+ @test_throws DimensionError Q (one (T), D, length= 1 ) + 1.0
125
+ @test_throws DimensionError Q (one (T), D, length= 1 ) - 1.0
126
+ @test_throws DimensionError 1.0 + Q (one (T), D, length= 1 )
127
+ @test_throws DimensionError 1.0 - Q (one (T), D, length= 1 )
128
128
end
129
129
130
130
x = Quantity (- 1.2 , length= 2 // 5 )
593
593
# Test deprecated method
594
594
q = 1.5 us " km/s"
595
595
@test expand_units (q) == uexpand (q)
596
+
597
+ # Test promotions:
598
+ x = Quantity {Float32,SymbolicDimensions{Rational{Int}}} (0.2 us " km/s" )
599
+ y = 0.5 us " km/s"
600
+ qa = [x, y]
601
+ @test qa isa Vector{Quantity{Float64,SymbolicDimensions{Rational{Int}}}}
596
602
end
597
603
598
604
@testset " uconvert" begin
671
677
qarr1 = QuantityArray (randn (3 ), u " km/s" )
672
678
qarr2 = qarr1
673
679
@test convert (typeof (qarr2), qarr2) === qarr1
680
+
681
+ x = 1.0 u " m"
682
+ y = x ^ (3 // 2 )
683
+ @test y == Quantity (1.0 , length= 3 // 2 )
684
+ @test typeof (y) == Quantity{Float64,DEFAULT_DIM_TYPE}
674
685
end
675
686
676
687
@testset " Arrays" begin
989
1000
@test x isa Vector{<: GenericQuantity{Float64,<:Dimensions} }
990
1001
@test ustrip (x[1 ]) == 500.0
991
1002
@test ustrip (x[2 ]) == 1.0
1003
+
1004
+ x = [GenericQuantity ([1.0 , 2.0 ]), GenericQuantity ([3f0 , 4f0 ], Dimensions{Rational{Int}}, length= 1 )]
1005
+ @test x isa Vector{GenericQuantity{Vector{Float64},Dimensions{Rational{Int}}}}
992
1006
end
993
1007
994
1008
@testset " GenericQuantity broadcasting" begin
0 commit comments