847
847
out = x ^ (1 + 2im )
848
848
@test typeof (out) == with_type_parameters (promote_quantity_on_value (Q, ComplexF64), Complex{Float64}, DEFAULT_DIM_TYPE)
849
849
@test ustrip (out) ≈ 0.5 ^ (1 + 2im )
850
+
851
+ for CT in (Complex, Complex{Float32})
852
+ x = Q (1.0 )
853
+ @test CT (x) == CT (1.0 )
854
+ @test typeof (CT (x)) <: CT
855
+ x = Q (1.0 , length= 1 )
856
+ @test_throws AssertionError CT (x)
857
+ end
858
+ end
859
+ end
860
+
861
+ @testset " Bool" begin
862
+ for Q in (RealQuantity, Quantity, GenericQuantity)
863
+ x = Q (1.0 u " 1" )
864
+ @test Bool (x) == true
865
+ @test Bool (ustrip (x)) == true
866
+ @test Bool (Q (0.0 u " m" )) == false
867
+ @test Bool (ustrip (Q (0.0 u " m" ))) == false
868
+ x = Q (1.0 u " m" )
869
+ @test_throws AssertionError Bool (x)
850
870
end
851
871
end
852
872
end
@@ -1266,7 +1286,7 @@ end
1266
1286
:nextfloat , :prevfloat , :identity , :transpose ,
1267
1287
:copysign , :flipsign , :modf ,
1268
1288
:floor , :trunc , :ceil , :significand ,
1269
- :ldexp , :round , # :mod
1289
+ :ldexp , :round , :mod
1270
1290
)
1271
1291
for Q in (RealQuantity, Quantity, GenericQuantity), D in (Dimensions, SymbolicDimensions), f in functions
1272
1292
T = f in (:abs , :real , :imag , :conj ) ? ComplexF64 : Float64
@@ -1280,17 +1300,31 @@ end
1280
1300
@eval @test $ f ($ qx_dimensions)[$ i] == $ Q ($ f ($ x)[$ i], $ dim)
1281
1301
end
1282
1302
end
1283
- elseif f in (:copysign , :flipsign , :rem ) # Functions that need multiple inputs
1303
+ elseif f in (:copysign , :flipsign , :rem , :mod ) # Functions that need multiple inputs
1284
1304
for x in 5 rand (T, 3 ) .- 2.5
1285
1305
for y in 5 rand (T, 3 ) .- 2.5
1286
1306
dim = convert (D, dimension (u " m/s" ))
1287
1307
qx_dimensions = Q (x, dim)
1288
1308
qy_dimensions = Q (y, dim)
1289
1309
@eval @test $ f ($ qx_dimensions, $ qy_dimensions) == $ Q ($ f ($ x, $ y), $ dim)
1290
- if f in (:copysign , :flipsign , :mod )
1310
+ if f in (:copysign , :flipsign )
1291
1311
# Also do test without dimensions
1292
1312
@eval @test $ f ($ x, $ qy_dimensions) == $ f ($ x, $ y)
1293
1313
@eval @test $ f ($ qx_dimensions, $ y) == $ Q ($ f ($ x, $ y), $ dim)
1314
+ elseif f in (:rem , :mod )
1315
+ # Also do test without dimensions (need dimensionless)
1316
+ qx_dimensionless = Q (x, D)
1317
+ qy_dimensionless = Q (y, D)
1318
+ @eval @test $ f ($ x, $ qy_dimensionless) == $ Q ($ f ($ x, $ y), $ D)
1319
+ @eval @test $ f ($ qx_dimensionless, $ y) == $ Q ($ f ($ x, $ y), $ D)
1320
+ @eval @test_throws DimensionError $ f ($ qx_dimensions, $ y)
1321
+ @eval @test_throws DimensionError $ f ($ x, $ qy_dimensions)
1322
+ if f == :rem
1323
+ # Can also do other rounding modes
1324
+ for r in (:RoundFromZero , :RoundNearest , :RoundUp , :RoundDown )
1325
+ @eval @test $ f ($ qx_dimensions, $ qy_dimensions, $ r) == $ Q ($ f ($ x, $ y, $ r), $ dim)
1326
+ end
1327
+ end
1294
1328
end
1295
1329
end
1296
1330
end
0 commit comments