Skip to content

Coverage with Julia >= 1.0 - #365

Open
PatrickHaecker wants to merge 2 commits into
JuliaMath:masterfrom
PatrickHaecker:coverage_with_Julia_1.0
Open

PatrickHaecker wants to merge 2 commits into
JuliaMath:masterfrom
PatrickHaecker:coverage_with_Julia_1.0

Conversation

@PatrickHaecker

Copy link
Copy Markdown
Collaborator

This is the (hopefully) uncontroversial part of #350, i.e. all changes which close coverage gaps while not bumping the dependency of the Julia version.

#350 then sits on top of this PR and will become smaller once the current PR is merged.

Patrick Häcker added 2 commits October 18, 2026 04:07
Covers reductions over empty and one-element arrays, `checked_mul` for
`f == 0`, the generic `AbstractFloat` conversion of `Normed`, hashing of
values that equal a `Rational` (which goes through `decompose`), `%` of a
foreign `Real` type, and the deprecated `floattype` fallback.

The reductions, the hashing and `%` behave the same for `Fixed` and
`Normed`, so common test functions check them over many raw types and
fractional bits.
`Normed{UInt8,f}` requires `1 <= f <= 8`, so after the checks for
`f <= 7` only `f == 8` remains and the final `0.0f0` could never be
returned.
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.87%. Comparing base (d62abf3) to head (aed366b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #365      +/-   ##
==========================================
+ Coverage   96.75%   98.87%   +2.12%     
==========================================
  Files           7        7              
  Lines         800      799       -1     
==========================================
+ Hits          774      790      +16     
+ Misses         26        9      -17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimikage kimikage left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments, but since this involves little changes to the main code, it's okay to merge this.

As for the code coverage, see also: #360 (comment)

Comment thread src/normed.jl
Comment on lines -160 to -161
f == 8 && return Float32(Int32(x.i) * 0x155) * @f32(0xc0f0fdp-40)
0.0f0

Copy link
Copy Markdown
Collaborator

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 f since 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 f is intended to be an Int (Int64 or Int32), intentionally no type restrictions have been imposed.
This allows for “hacks” like the following:

julia> Normed{UInt8, true}(5)
5.0N7ftrue

Comment thread test/traits.jl
Comment on lines 19 to +21
@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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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
# TODO: eliminate `@test_skip` when the deprecated fallback is eliminated. See #177.
# Meanwhile, verify that the fallback warns and returns the type unchanged.
@test_skip(@test_throws MethodError floattype(MyReal))
@test (@test_logs (:warn, r"fallback definition of `floattype`") floattype(MyReal)) === MyReal

This is a matter of personal preference, but I think leading with # TODO would make it clearer that these two tests are a pair.
@test_skipped is probably a typo.

Comment thread test/common.jl
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 unsafe_trunc is implemented for custom types?

Comment thread test/normed.jl

# 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)

@kimikage kimikage Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this invoke actually called in real codes?
IIUC, in the case of a non-concrete type, dynamic dispatch should call the respective specialized methods.

I think it would probably be better to prepare a Unsigned or AbstractFloat type for testing purposes.

Also, although this is outside the scope of this PR, it might be a good idea to include BFloat16 in the test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants