Skip to content

Commit

Permalink
Base.hash for test statistics (JuliaLang#670)
Browse files Browse the repository at this point in the history
* Base.hash for test statistics

* woops, simple equality
  • Loading branch information
palday authored Mar 15, 2021
1 parent 7089961 commit f32d0f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/statmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,14 @@ for op in [:(==), :<, :≤, :>, :≥, :(isless), :(isequal)] # isless and < to p
end
end

Base.hash(x::Union{TestStat, PValue}, h::UInt) = hash(x.v, h)

# necessary to avoid a method ambiguity with isless(::TestStat, NaN)
Base.isless(x::Union{TestStat, PValue}, y::AbstractFloat) = isless(x.v, y)
Base.isless(y::AbstractFloat, x::Union{TestStat, PValue},) = isless(y, x.v)
Base.isequal(y::AbstractFloat, x::Union{TestStat, PValue}) = isequal(y, x.v)
Base.isequal(x::Union{TestStat, PValue}, y::AbstractFloat) = isequal(x.v, y)


Base.isapprox(x::Union{TestStat, PValue}, y::Real; kwargs...) = isapprox(x.v, y; kwargs...)
Base.isapprox(y::Real, x::Union{TestStat, PValue}; kwargs...) = isapprox(y, x.v; kwargs...)
Base.isapprox(x1::Union{TestStat, PValue}, x2::Union{TestStat, PValue}; kwargs...) = isapprox(x1.v, x2.v; kwargs...)
Expand Down
2 changes: 2 additions & 0 deletions test/statmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ end
@test Rational(1,3) T(1/3) atol=0.01
@test T(Rational(1,3)) isa Real
@test T(T(0.05)) === T(0.05)
@test hash(T(0.05)) == hash(0.05)
@test hash(T(0.05), UInt(42)) == hash(0.05, UInt(42))
end
end

Expand Down

0 comments on commit f32d0f1

Please sign in to comment.