@@ -105,13 +105,20 @@ end
105
105
@test ismissing (missing * " a" )
106
106
end
107
107
108
+ # Emulate a unitful type such as Dates.Minute
109
+ struct Unit
110
+ value:: Int
111
+ end
112
+ Base. zero (:: Type{Unit} ) = Unit (0 )
113
+ Base. one (:: Type{Unit} ) = 1
114
+
108
115
@testset " elementary functions" begin
109
116
elementary_functions = [abs, abs2, sign,
110
117
acos, acosh, asin, asinh, atan, atanh, sin, sinh,
111
118
conj, cos, cosh, tan, tanh,
112
119
exp, exp2, expm1, log, log10, log1p, log2,
113
120
exponent, sqrt, gamma, lgamma,
114
- identity, zero,
121
+ identity, zero, one, oneunit,
115
122
iseven, isodd, ispow2,
116
123
isfinite, isinf, isnan, iszero,
117
124
isinteger, isreal, isempty, transpose, float]
121
128
@test ismissing (f (missing ))
122
129
end
123
130
124
- @test zero (Union{Int, Missing}) === 0
125
- @test zero (Union{Float64, Missing}) === 0.0
131
+ for T in (Int, Float64)
132
+ @test zero (Union{T, Missing}) === T (0 )
133
+ @test one (Union{T, Missing}) === T (1 )
134
+ @test oneunit (Union{T, Missing}) === T (1 )
135
+ end
136
+
137
+ for T in (Unit,)
138
+ @test zero (Union{T, Missing}) === T (0 )
139
+ @test one (Union{T, Missing}) === 1
140
+ @test oneunit (Union{T, Missing}) === T (1 )
141
+ end
142
+
126
143
@test_throws MethodError zero (Any)
144
+ @test_throws MethodError one (Any)
145
+ @test_throws MethodError oneunit (Any)
146
+
127
147
@test_throws MethodError zero (String)
128
148
@test_throws MethodError zero (Union{String, Missing})
129
149
end
0 commit comments