@@ -1089,3 +1089,46 @@ end
1089
1089
@test convert (typeof (qx), qy)[1 ] == convert (Quantity{Float64}, qy[1 ])
1090
1090
end
1091
1091
end
1092
+
1093
+ @testset " Dimensionless functions" begin
1094
+ functions = (
1095
+ :sin , :cos , :tan , :sinh , :cosh , :tanh , :asin , :acos ,
1096
+ :asinh , :acosh , :atanh , :sec , :csc , :cot , :asec , :acsc , :acot , :sech , :csch ,
1097
+ :coth , :asech , :acsch , :acoth , :sinc , :cosc , :cosd , :cotd , :cscd , :secd ,
1098
+ :sinpi , :cospi , :sind , :tand , :acosd , :acotd , :acscd , :asecd , :asind ,
1099
+ :log , :log2 , :log10 , :log1p , :exp , :exp2 , :exp10 , :expm1 , :frexp , :exponent ,
1100
+ :atan , :atand
1101
+ )
1102
+ function is_input_valid (f, x)
1103
+ try
1104
+ f (x)
1105
+ catch e
1106
+ e isa DomainError && return false
1107
+ rethrow (e)
1108
+ end
1109
+ return true
1110
+ end
1111
+ for Q in (Quantity, GenericQuantity), D in (Dimensions, SymbolicDimensions), f in functions
1112
+ # Only test on valid domain
1113
+ valid_inputs = filter (
1114
+ x -> is_input_valid (eval (f), x),
1115
+ 5 rand (100 ) .- 2.5
1116
+ )
1117
+ for x in valid_inputs[1 : 3 ]
1118
+ qx_dimensionless = Quantity (x, D)
1119
+ qx_dimensions = Quantity (x, convert (D, dimension (u " m/s" )))
1120
+ @eval @test $ f ($ qx_dimensionless) == $ f ($ x)
1121
+ @eval @test_throws DimensionError $ f ($ qx_dimensions)
1122
+ if f in (:atan , :atand )
1123
+ for y in valid_inputs[end - 3 : end ]
1124
+ qy_dimensionless = Quantity (y, D)
1125
+ qy_dimensions = Quantity (y, convert (D, dimension (u " m/s" )))
1126
+ @eval @test $ f ($ qy_dimensionless, $ qx_dimensionless) == $ f ($ y, $ x)
1127
+ @eval @test $ f ($ qy_dimensions, $ qx_dimensions) == $ f ($ y, $ x)
1128
+ @eval @test_throws DimensionError $ f ($ qy_dimensions, $ x)
1129
+ @eval @test_throws DimensionError $ f ($ y, $ qx_dimensions)
1130
+ end
1131
+ end
1132
+ end
1133
+ end
1134
+ end
0 commit comments