@@ -98,6 +98,27 @@ using Test
9898 @test uluminosity (y) == R (0 )
9999 @test uamount (y) == R (0 )
100100 @test ustrip (y) ≈ T (0.2 ^ 2.1 )
101+
102+ dimensionless = Quantity (one (T), R)
103+ y = T (2 ) + dimensionless
104+ @test ustrip (y) == T (3 )
105+ @test dimension (y) == Dimensions (R)
106+ @test typeof (y) == Quantity{T,R}
107+
108+ y = T (2 ) - dimensionless
109+ @test ustrip (y) == T (1 )
110+ @test dimension (y) == Dimensions (R)
111+ @test typeof (y) == Quantity{T,R}
112+
113+ y = dimensionless + T (2 )
114+ @test ustrip (y) == T (3 )
115+ y = dimensionless - T (2 )
116+ @test ustrip (y) == T (- 1 )
117+
118+ @test_throws DimensionError Quantity (one (T), R, length= 1 ) + 1.0
119+ @test_throws DimensionError Quantity (one (T), R, length= 1 ) - 1.0
120+ @test_throws DimensionError 1.0 + Quantity (one (T), R, length= 1 )
121+ @test_throws DimensionError 1.0 - Quantity (one (T), R, length= 1 )
101122 end
102123
103124 x = Quantity (- 1.2 , length= 2 // 5 )
@@ -150,20 +171,35 @@ end
150171
151172 @test Dimensions {Int8} ([0 for i= 1 : length (DIMENSION_NAMES)]. .. ) == Dimensions {Int8} ()
152173
153- @test zero (Quantity{ComplexF64,Int8} ) + Quantity (1 ) == Quantity (1.0 + 0.0im , length= Int8 (0 ))
154- @test one (Quantity{ComplexF64,Int8} ) - Quantity (1 ) == Quantity (0.0 + 0.0im , length= Int8 (0 ))
174+ @test zero (Quantity ( 0.0 + 0.0im ) ) + Quantity (1 ) == Quantity (1.0 + 0.0im , length= Int8 (0 ))
175+ @test oneunit (Quantity ( 0.0 + 0.0im ) ) - Quantity (1 ) == Quantity (0.0 + 0.0im , length= Int8 (0 ))
155176 @test typeof (one (Dimensions{Int16})) == Dimensions{Int16}
156177 @test one (Dimensions{Int16}) == Dimensions (mass= Int16 (0 ))
157178
158- @test zero (Quantity{ComplexF64} ) == Quantity (0.0 + 0.0im )
179+ @test zero (Quantity ( 0.0im ) ) == Quantity (0.0 + 0.0im )
159180 @test one (Quantity{ComplexF64}) == Quantity (1.0 + 0.0im )
160181
161- @test zero (Quantity) == Quantity (0.0 )
162- @test typeof (zero (Quantity)) == Quantity{DEFAULT_VALUE_TYPE,DEFAULT_DIM_TYPE}
163- @test one (Quantity) - Quantity (1 ) == Quantity (0.0 )
164- @test typeof (one (Quantity)) == Quantity{DEFAULT_VALUE_TYPE,DEFAULT_DIM_TYPE}
165- @test typeof (one (Dimensions)) == Dimensions{DEFAULT_DIM_TYPE}
182+ @test zero (Quantity (0.0 )) == Quantity (0.0 )
183+ @test typeof (zero (Quantity (0.0 ))) == Quantity{Float64,DEFAULT_DIM_TYPE}
184+ @test oneunit (Quantity (1.0 )) - Quantity (1.0 ) == Quantity (0.0 )
185+ @test typeof (one (Quantity (1.0 ))) == Quantity{DEFAULT_VALUE_TYPE,DEFAULT_DIM_TYPE}
166186 @test one (Dimensions) == Dimensions ()
187+ @test one (Dimensions ()) == Dimensions ()
188+ @test typeof (one (Quantity)) == Quantity{DEFAULT_VALUE_TYPE,DEFAULT_DIM_TYPE}
189+ @test ustrip (one (Quantity)) === one (DEFAULT_VALUE_TYPE)
190+
191+ x = Quantity (1 , length= 1 )
192+
193+ @test zero (x) == Quantity (0 , length= 1 )
194+ @test typeof (zero (x)) == Quantity{Int64,DEFAULT_DIM_TYPE}
195+
196+ # Invalid calls:
197+ @test_throws ErrorException zero (Quantity)
198+ @test_throws ErrorException zero (Dimensions ())
199+ @test_throws ErrorException zero (Dimensions)
200+ @test_throws ErrorException oneunit (Quantity)
201+ @test_throws ErrorException oneunit (Dimensions ())
202+ @test_throws ErrorException oneunit (Dimensions)
167203
168204 @test sqrt (z * - 1 ) == Quantity (sqrt (52 ), length= 1 // 2 , mass= 1 )
169205 @test cbrt (z) == Quantity (cbrt (- 52 ), length= 1 // 3 , mass= 2 // 3 )
0 commit comments