Skip to content

Commit f1ad8fb

Browse files
committed
increase coverage
1 parent e0704f8 commit f1ad8fb

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

src/Infinities.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ string(::Infinity) = "∞"
3131
convert(::Type{Float64}, ::Infinity) = Inf64
3232
convert(::Type{Float32}, ::Infinity) = Inf32
3333
convert(::Type{Float16}, ::Infinity) = Inf16
34-
Float64(::Infinity) = convert(Float64, ∞)
35-
Float32(::Infinity) = convert(Float32, ∞)
36-
Float16(::Infinity) = convert(Float16, ∞)
37-
BigFloat(::Infinity) = BigFloat(Inf)
34+
Base.Float64(::Infinity) = convert(Float64, ∞)
35+
Base.Float32(::Infinity) = convert(Float32, ∞)
36+
Base.Float16(::Infinity) = convert(Float16, ∞)
37+
Base.BigFloat(::Infinity) = BigFloat(Inf)
3838
convert(::Type{AF}, ::Infinity) where AF<:AbstractFloat = convert(AF, Inf)
3939

4040

@@ -358,10 +358,6 @@ end
358358
*(a::Number, y::ComplexInfinity) = ComplexInfinity(y.signbit+angle(a)/π)
359359
*(y::ComplexInfinity, a::Number) = a*y
360360

361-
*(a::Number, y::Infinity) = a*ComplexInfinity(y)
362-
*(y::Infinity, a::Number) = ComplexInfinity(y)*a
363-
*(y::RealInfinity, a::Number) = ComplexInfinity(y)*a
364-
365361
*(a::Complex, y::Infinity) = a*ComplexInfinity(y)
366362
*(y::Infinity, a::Complex) = ComplexInfinity(y)*a
367363

@@ -409,8 +405,8 @@ Base.Checked.checked_add(x::RealInfinity, ::Integer) = x
409405

410406
Base.Checked.checked_mul(x::Integer, ::Infinity) = sign(x)*
411407
Base.Checked.checked_mul(::Infinity, x::Integer) = sign(x)*
412-
Base.Checked.checked_mul(x::Integer, ::RealInfinity) = sign(x)*
413-
Base.Checked.checked_mul(::RealInfinity, x::Integer) = sign(x)*
408+
Base.Checked.checked_mul(x::Integer, y::RealInfinity) = sign(x)*y
409+
Base.Checked.checked_mul(y::RealInfinity, x::Integer) = y*sign(x)
414410

415411

416412

test/runtests.jl

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ import Infinities: Infinity
1111

1212
@test +
1313

14-
@test isless(1, ∞)
15-
@test !isless(Inf, ∞)
16-
@test !isless(∞, Inf)
17-
@test !isless(∞, 1)
18-
@test !isless(∞, ∞)
19-
@test !(∞ < ∞)
20-
@test
21-
@test !(∞ > ∞)
22-
@test
23-
24-
@test 5 <&& 5  ∞
25-
@test !(5 > ∞) && !(5  ∞)
14+
@testset "inequalities" begin
15+
@test isless(1, ∞)
16+
@test !isless(Inf, ∞)
17+
@test !isless(∞, Inf)
18+
@test !isless(∞, 1)
19+
@test !isless(∞, ∞)
20+
@test !(∞ < ∞)
21+
@test
22+
@test !(∞ > ∞)
23+
@test
24+
25+
@test 5 <&& 5  ∞
26+
@test !(∞ < 5) && !(∞  5)
27+
@test> 5 && 5
28+
@test !(5 > ∞) && !(5  ∞)
29+
end
2630

2731
@test+
2832
@test+ 1 1 ++ 1.0 1.0 +
@@ -82,7 +86,7 @@ import Infinities: Infinity
8286
@test convert(Float64, ∞) Float64(∞) Inf
8387
@test convert(Float32, ∞) Float32(∞) Inf32
8488
@test convert(Float16, ∞) Float16(∞) Inf16
85-
@test convert(BigFloat, ∞)::BigFloat == BigFloat(Inf)
89+
@test convert(BigFloat, ∞)::BigFloat == BigFloat(∞)::BigFloat == BigFloat(Inf)
8690
end
8791

8892
@testset "checked" begin
@@ -95,6 +99,7 @@ import Infinities: Infinity
9599
@test RealInfinity(∞) convert(RealInfinity, ∞) RealInfinity()
96100
RealInfinity(false) RealInfinity(RealInfinity())
97101

102+
@test promote_type(Infinity, RealInfinity) == RealInfinity
98103
@test promote(∞, RealInfinity()) (RealInfinity(),RealInfinity())
99104

100105
@test - RealInfinity(true)
@@ -196,7 +201,8 @@ import Infinities: Infinity
196201
@test checked_sub(5, ∞) checked_sub(5, RealInfinity()) -
197202
@test checked_sub(-∞, 5) -
198203
@test checked_add(5, -∞) checked_add(-∞, 5) -
199-
@test checked_mul(-5, ∞) -
204+
@test checked_mul(-5, ∞) checked_mul(∞, -5) -
205+
@test checked_mul(-5, -∞) checked_mul(-∞, -5) RealInfinity()
200206
end
201207
end
202208

@@ -211,6 +217,7 @@ import Infinities: Infinity
211217
@test !isfinite(ComplexInfinity())
212218

213219
@test promote(∞, RealInfinity(), ComplexInfinity()) ntuple(_ -> ComplexInfinity(), 3)
220+
@test promote_type(Infinity, ComplexInfinity{Bool}) == promote_type(RealInfinity, ComplexInfinity{Bool}) == ComplexInfinity{Bool}
214221

215222

216223
@test ComplexInfinity(∞) ==
@@ -223,6 +230,8 @@ import Infinities: Infinity
223230
@test RealInfinity() + im im + RealInfinity() RealInfinity() + 1.0im 1.0im + RealInfinity() RealInfinity() - im RealInfinity() - 1.0im ComplexInfinity()
224231

225232
@test im - 1.0im - -ComplexInfinity()
233+
@test im - ComplexInfinity() 1.0im - ComplexInfinity() -ComplexInfinity()
234+
@test ComplexInfinity() - im ComplexInfinity() - 1.0im ComplexInfinity()
226235

227236
@test ComplexInfinity() + ComplexInfinity() + RealInfinity()
228237
+ ComplexInfinity() RealInfinity() + ComplexInfinity() ComplexInfinity()
@@ -235,6 +244,7 @@ import Infinities: Infinity
235244
ComplexInfinity() * ComplexInfinity() * RealInfinity() ComplexInfinity()
236245

237246
@test 2.0im**2.0im 2.0im * RealInfinity() RealInfinity() * 2.0im ComplexInfinity(1/2)
247+
@test 2ComplexInfinity() ComplexInfinity()*2 ComplexInfinity()
238248

239249
@test exp(im*π/4)*== Inf+im*Inf
240250
@test exp(im*π/4)+==
@@ -247,7 +257,9 @@ import Infinities: Infinity
247257
@test !isless(ComplexInfinity(), 5)
248258

249259
@test 5 < ComplexInfinity() && 5 ComplexInfinity()
260+
@test !(ComplexInfinity() < 5) && !(ComplexInfinity() 5)
250261
@test 5 > -ComplexInfinity() && 5 -ComplexInfinity()
262+
@test ComplexInfinity() > 5 && ComplexInfinity()   5
251263

252264
@test 1 + ComplexInfinity() 1.0 + ComplexInfinity() ComplexInfinity() + 1 ComplexInfinity() + 1.0 ComplexInfinity()
253265
@test 5 * ComplexInfinity() ComplexInfinity()
@@ -265,6 +277,11 @@ import Infinities: Infinity
265277
@test min(ComplexInfinity(), 5) min(5,ComplexInfinity()) 5
266278
@test max(ComplexInfinity(), 5) max(5,ComplexInfinity()) ComplexInfinity()
267279
end
280+
281+
@testset "fld/cld/div" begin
282+
@test div(ComplexInfinity(), 5) fld(ComplexInfinity(), 5) ComplexInfinity()
283+
@test div(-ComplexInfinity(),2) -ComplexInfinity()
284+
end
268285
end
269286
end
270287

test/test_cardinality.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using Infinities, Base64, Test
1717
@test 5 < ℵ₀ && 5  ℵ₀
1818
@test !(ℵ₀ < 5) && !(ℵ₀  5)
1919
@test ℵ₀ > 5 && ℵ₀ 5
20+
@test !(5 > ℵ₀) && !(5  ℵ₀)
2021

2122
@test string(ℵ₀) == stringmime("text/plain", ℵ₀) == "ℵ₀"
2223
@test string(ℵ₁) == stringmime("text/plain", ℵ₁) == "ℵ₁"

0 commit comments

Comments
 (0)