Skip to content

Commit

Permalink
add a minimal test for custom weights implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed May 16, 2024
1 parent 9913c61 commit 588ac75
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/weights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,17 @@ end
end
end

@testset "custom weight types" begin
struct MyWeights <: AbstractWeights{Float64, Float64, Vector{Float64}}
values::Vector{Float64}
sum::Float64
end
MyWeights(values) = MyWeights(values, sum(values))

@test mean([1, 2, 3], MyWeights([1, 4, 10])) 2.6
@test mean([1, 2, 3], MyWeights([NaN, 4, 10])) |> isnan
@test mode([1, 2, 3], MyWeights([1, 4, 10])) == 3
@test_throws ArgumentError mode([1, 2, 3], MyWeights([NaN, 4, 10]))
end

end # @testset StatsBase.Weights

0 comments on commit 588ac75

Please sign in to comment.