1- module OnlineStatsTests
2-
31using OnlineStats, Test, Statistics, Random, LinearAlgebra, Dates
42O = OnlineStats
5- import StatsBase: countmap, fit, Histogram
3+ import StatsBase: countmap, fit, Histogram, sample
64import DataStructures: OrderedDict, SortedDict
75
86const y = randn (1000 )
@@ -49,6 +47,7 @@ function test_merge(o, y1, y2, compare = ≈; kw...)
4947 @test nobs (o) == nobs (o2) == nrows (y1) + nrows (y2)
5048end
5149
50+ # @test compare(fo(fit!(o,y)), fy(y))
5251function test_exact (o, y, fo, fy:: Function , compare = ≈ ; kw... )
5352 fit! (o, y)
5453 for (v1, v2) in zip (fo (o), fy (y))
@@ -58,6 +57,8 @@ function test_exact(o, y, fo, fy::Function, compare = ≈; kw...)
5857 end
5958 @test nobs (o) == nrows (y)
6059end
60+
61+ # @test compare(fo(fit!(o,y )), fy)
6162function test_exact (o, y, fo, fy, compare = ≈ ; kw... )
6263 fit! (o, y)
6364 for (v1, v2) in zip (fo (o), fy)
@@ -73,6 +74,17 @@ nrows(m::AbstractMatrix) = size(m, 1)
7374nrows (t:: Tuple ) = length (t[2 ])
7475nrows (y:: Base.Iterators.Zip2 ) = length (y)
7576
77+ function testfit (o:: OnlineStat , y, val, compare = ≈ )
78+ @test nobs (o) == nobs (o)
79+ @test compare (value (fit! (o, y)), val)
80+ end
81+
82+ function testmerge (o:: OnlineStat , y, compare = ≈ ; n= 10 )
83+ for i in 1 : n
84+ a = sample (y, floor (Int, length (y)/ 2 ); replace= false )
85+ b = sample (y, floor (Int, length (y)/ 2 ); replace= false )
86+ end
87+ end
7688
7789# -----------------------------------------------------------------------# utils
7890println (" \n\n " )
395407 @inferred Mean ()
396408 @inferred Mean (Complex{Float64})
397409 test_exact (Mean (), y, mean, mean)
410+ test_exact (Mean (BigFloat), big .(y), mean, mean, ≈ , atol= 1e-16 )
398411 test_exact (Mean (Complex{Float64}), y + y2* im, mean, mean)
399412 test_merge (Mean (), y, y2)
400413end
609622end
610623
611624include (" test_kahan.jl" )
612-
613- end # module
0 commit comments