Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Sep 4, 2018
1 parent 4f9028c commit 40b2ea7
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions stdlib/Statistics/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
end

@testset "mean" begin
@test_throws ArgumentError mean(())
@test_throws MethodError mean(())
@test mean((1,2,3)) === 2.
@test mean([0]) === 0.
@test mean([1.]) === 1.
Expand Down Expand Up @@ -88,8 +88,17 @@ end
@test mean(skipmissing([1, missing, 2])) === 1.5
@test isequal(mean(Complex{Float64}[]), NaN+NaN*im)
@test isequal(mean(skipmissing(Complex{Float64}[])), NaN+NaN*im)
@test mean(Complex{Float64}[]) isa Complex{Float64}
@test mean(skipmissing(Complex{Float64}[])) isa Complex{Float64}
@test isequal(mean(abs, Complex{Float64}[]), NaN)
@test isequal(mean(abs, skipmissing(Complex{Float64}[])), NaN)
@test mean(abs, Complex{Float64}[]) isa Float64
@test mean(abs, skipmissing(Complex{Float64}[])) isa Float64
@test_throws MethodError mean([])
@test_throws MethodError mean(skipmissing([]))
@test_throws MethodError mean((1 for i in 2:1))
@test mean(Int[]) isa Float64
@test mean(skipmissing(Int[])) isa Float64

# Check that small types are accumulated using wider type
for T in (Int8, UInt8)
Expand All @@ -113,10 +122,10 @@ end
@testset "var & std" begin
# edge case: empty vector
# iterable; this has to throw for type stability
@test_throws ArgumentError var(())
@test_throws ArgumentError var((); corrected=false)
@test_throws ArgumentError var((); mean=2)
@test_throws ArgumentError var((); mean=2, corrected=false)
@test_throws MethodError var(())
@test_throws MethodError var((); corrected=false)
@test_throws MethodError var((); mean=2)
@test_throws MethodError var((); mean=2, corrected=false)
# reduction
@test isnan(var(Int[]))
@test isnan(var(Int[]; corrected=false))
Expand Down Expand Up @@ -250,8 +259,15 @@ end
@test f(skipmissing([1, missing, 2]), 0) === f([1, 2], 0)
end

@test isequal(mean(Complex{Float64}[]), NaN)
@test isequal(mean(skipmissing(Complex{Float64}[])), NaN)
@test isequal(var(Complex{Float64}[]), NaN)
@test isequal(var(skipmissing(Complex{Float64}[])), NaN)
@test var(Complex{Float64}[]) isa Float64
@test var(skipmissing(Complex{Float64}[])) isa Float64
@test_throws MethodError var([])
@test_throws MethodError var(skipmissing([]))
@test_throws ArgumentError var((1 for i in 2:1))
@test var(Int[]) isa Float64
@test var(skipmissing(Int[])) isa Float64
end

function safe_cov(x, y, zm::Bool, cr::Bool)
Expand Down

0 comments on commit 40b2ea7

Please sign in to comment.