diff --git a/test/weights.jl b/test/weights.jl index 133fe8a88..76277e02f 100644 --- a/test/weights.jl +++ b/test/weights.jl @@ -1,6 +1,15 @@ using StatsBase using LinearAlgebra, Random, SparseArrays, Test + +# minimal custom weights type for tests below +struct MyWeights <: AbstractWeights{Float64, Float64, Vector{Float64}} + values::Vector{Float64} + sum::Float64 +end +MyWeights(values) = MyWeights(values, sum(values)) + + @testset "StatsBase.Weights" begin weight_funcs = (weights, aweights, fweights, pweights) @@ -611,12 +620,6 @@ 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