From 588ac75ee4c363c05ad57fc736e81074ea418dc0 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Thu, 16 May 2024 08:22:35 -0400 Subject: [PATCH] add a minimal test for custom weights implementations --- test/weights.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/weights.jl b/test/weights.jl index 2180c88a4..133fe8a88 100644 --- a/test/weights.jl +++ b/test/weights.jl @@ -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