Skip to content

Commit

Permalink
fix name and add tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Jun 24, 2023
1 parent cfe56bb commit 9b69dc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/OnlineStatsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Base.show(io::IO, o::OnlineStat)
show(IOContext(io, :compact => true, :displaysize => (1, 70)), value(o))
end
function name(T::Type, withmodule = false, withparams = true)
s = string(T)
s = "OnlineStatsBase." * string(T)
s = withmodule ? s : replace(s, r"([a-zA-Z]*\.)" => "")
return withparams ? s : replace(s, r"\{(.*)" => "")
end
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OnlineStatsBase: _fit!, _merge!

O = OnlineStatsBase

include("test_stats.jl")


#-----------------------------------------------------------------------# Misc
@testset "Misc." begin
Expand All @@ -23,6 +23,15 @@ include("test_stats.jl")
@test_throws Exception OnlineStatsBase._fit!(Mean(), "a")
@test collect(OnlineStatsBase.neighbors([1,3,5])) == [(1,3), (3,5)]
@test isnan(value(fit!(Variance(), NaN)))

@testset "name" begin
name = OnlineStatsBase.name
o = Mean()
@test name(o, false, false) == "Mean"
@test name(o, true, false) == "OnlineStatsBase.Mean"
@test name(o, false, true) == "Mean{Float64, EqualWeight}"
@test name(o, true, true) == "OnlineStatsBase.Mean{Float64, EqualWeight}"
end
end

@testset "Broadcasting" begin
Expand Down Expand Up @@ -75,3 +84,6 @@ end #Weight
@test isapprox(value(r1), value(r2))
@test nobs(r1) == nobs(r2)
end

#-----------------------------------------------------------------------------# test_stats.jl
include("test_stats.jl")

0 comments on commit 9b69dc1

Please sign in to comment.