-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.jl
36 lines (31 loc) · 848 Bytes
/
stats.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Test
using HDPHMM
using Distributions
import HDPHMM: UnnormalizedCategorical, enablemissing, disablemissing
@testset "UnnormalizedCategorical" begin
idx = (7,5)
p = zeros(10, 10)
p[idx...] = 10.0
d = UnnormalizedCategorical(p)
@test d.s == 10
@test rand(d) == idx
end
@testset "Missings" begin
# No errors if called multiple times
@test_nowarn enablemissing()
@test_nowarn enablemissing()
@test_nowarn disablemissing()
@test_nowarn disablemissing()
end
@testset "Missings $f" for f in [pdf, logpdf, Distributions.zval]
disablemissing()
@test_throws MethodError f(Normal(), missing)
enablemissing()
@test_nowarn f(Normal(), missing)
end
@testset "Vector" begin
d = Normal()
X = rand(d, 1000)
@test pdf(d, X) == pdf.(d, X)
@test logpdf(d, X) == logpdf.(d, X)
end