Repository navigation
Coverage with Julia >= 1.0 #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,11 +153,32 @@ function test_convert_from_nan(TX::Type) | |
| end | ||
| end | ||
|
|
||
| function test_hash_rational(TX::Type) | ||
| @testset "hash(::$X)" for X in target(TX, :i8, :i16, :i32, :i64; ex = :thin) | ||
| for x in (zero(X), eps(X), typemin(X), typemax(X)) | ||
| @test x == Rational(x) | ||
| @test hash(x) == hash(Rational(x)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # a `Real` type with only the methods that `x % X` needs | ||
| struct IntReal <: Real | ||
| i::Int | ||
| end | ||
| Base.:*(a::Integer, x::IntReal) = IntReal(a * x.i) | ||
| Base.:*(x::IntReal, a::AbstractFloat) = IntReal(Int(x.i * a)) | ||
| Base.isfinite(::IntReal) = true | ||
| Base.round(x::IntReal) = x | ||
| Base.unsafe_trunc(::Type{T}, x::IntReal) where {T <: Integer} = x.i % T | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is for testing (or, more specifically, for code coverage), I suppose it can't be helped, but is it realistic to expect that |
||
|
|
||
| function test_rem_type(TX::Type) | ||
| @testset "% $X" for X in target(TX, :i8, :i16; ex = :thin) | ||
| xs = typemin(X):0.1:typemax(X) | ||
| @test all(x -> x % X === X(x), xs) | ||
| @test wrapping_rem(2, X) === saturating_rem(2, X) === checked_rem(2, X) === 2 % X | ||
| @test IntReal(1) % X === 1 % X | ||
| @test IntReal(2) % X === 2 % X | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -400,6 +421,16 @@ function test_isinteger(TX::Type) | |
| end | ||
| end | ||
|
|
||
| function test_reductions_short(TX::Type) | ||
| @testset "sum/prod(::Vector{$X})" for X in target(TX; ex = :thin) | ||
| x = typemax(X) | ||
| @test sum(X[]) === 0.0 | ||
| @test prod(X[]) === 1.0 | ||
| @test sum([x]) === Float64(x) | ||
| @test prod([x]) === Float64(x) | ||
| end | ||
| end | ||
|
|
||
| function test_rand(TX::Type) | ||
| @testset "rand(::$X)" for X in target(TX; ex = :thin) | ||
| @test isa(rand(X), X) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,8 @@ end | |
| @test rationalize(Int16, 0.804N0f8) === Rational{Int16}(41//51) | ||
| @test rationalize(0.804N0f8, tol=0.002) === Rational{Int}(41//51) | ||
| @test rationalize(Int8, 0.804N0f8, tol=0.005) === Rational{Int8}(4//5) | ||
|
|
||
| test_hash_rational(Normed) | ||
| end | ||
|
|
||
| @testset "BigFloat conversions" begin | ||
|
|
@@ -252,6 +254,11 @@ end | |
| @test isa(y, T) | ||
| end | ||
|
|
||
| # the generic method serves `AbstractFloat` types without a dedicated method | ||
| for Tf in (Float16, Float32, Float64), x in (0.2N0f8, 0.2N0f16, 0.2N2f14, 0.2N0f32, 0.2N0f64) | ||
| @test invoke(Tf, Tuple{Normed}, x) === Tf(x) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this I think it would probably be better to prepare a Also, although this is outside the scope of this PR, it might be a good idea to include |
||
| end | ||
|
|
||
| for Tf in (Float16, Float32, Float64) | ||
| @testset "$Tf(::$N)" for N in target(Normed, :i8, :i16) | ||
| T = rawtype(N) | ||
|
|
@@ -672,6 +679,8 @@ end | |
| acmp = Float64(a[1])*Float64(a[2]) | ||
| @test prod(a) == acmp | ||
| @test prod(a, dims=1) == [acmp] | ||
|
|
||
| test_reductions_short(Normed) | ||
| end | ||
|
|
||
| @testset "reductions, Statistics" begin | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,4 +17,6 @@ struct MyReal <: Real end | |||||||||||||||
| @test floattype(typeof(π)) === Float64 | ||||||||||||||||
|
|
||||||||||||||||
| @test_skip(@test_throws MethodError floattype(MyReal)) # TODO: eliminate `@test_skipped` when depwarn is eliminated. See #177. | ||||||||||||||||
| # meanwhile, the deprecated fallback warns and returns the type unchanged | ||||||||||||||||
| @test (@test_logs (:warn, r"fallback definition of `floattype`") floattype(MyReal)) === MyReal | ||||||||||||||||
|
Comment on lines
19
to
+21
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is a matter of personal preference, but I think leading with |
||||||||||||||||
| end | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has been discussion regarding the support range of
fsince before Issue #311.Since this is a case where it is better to apply manual dispatch (or the equivalent), I have adopted the current "sentinel".
Although this loses the ability to act as a sentinel against future changes, I think it’s a reasonable change for the purpose of increasing current coverage.
Incidentally, while
fis intended to be anInt(Int64orInt32), intentionally no type restrictions have been imposed.This allows for “hacks” like the following: