Skip to content

Commit 1ec7d7a

Browse files
committed
working on tests
1 parent da40411 commit 1ec7d7a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

test/runtests.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Base.Iterators: take
44
using Random
55
using LinearAlgebra
66
using KeywordCalls
7+
using Statistics
78

89
function draw2(μ)
910
x = rand(μ)
@@ -17,17 +18,22 @@ end
1718
const sqrt2π = sqrt(2π)
1819

1920
@testset "Parameterized Measures" begin
20-
@measure Normal(μ,σ)
21-
@kwstruct Normal()
22-
23-
MeasureBase.basemeasure(::Normal)= (1/sqrt2π) * Lebesgue(ℝ)
24-
25-
MeasureBase.logdensity(d::Normal{(:μ,:σ)}, x) = -log(d.σ) - (x - d.μ)^2 / (2 * d.σ^2)
26-
MeasureBase.logdensity(d::Normal{()}, x) = -0.5 * x^2
21+
@measure Normal(μ,σ)
22+
@kwstruct Normal(μ)
23+
@kwstruct Normal()
24+
25+
MeasureBase.basemeasure(::Normal)= (1/sqrt2π) * Lebesgue(ℝ)
26+
MeasureBase.logdensity(d::Normal{(:μ,:σ)}, x) = -log(d.σ) - (x - d.μ)^2 / (2 * d.σ^2)
27+
MeasureBase.logdensity(d::Normal{(:μ,)}, x) = - (x - d.μ)^2 / 2
28+
MeasureBase.logdensity(d::Normal{()}, x) = - x^2 / 2
29+
30+
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{(:μ,:σ)}) = d.μ + d.σ * randn(rng, T)
31+
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{(:μ,)}) = d.μ + randn(rng, T)
32+
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{()}) = randn(rng, T)
2733

28-
@test Normal(2,4) == Normal=2, σ=4)
29-
@test Normal=4, μ=2) == Normal=2, σ=4)
30-
@test logdensity(Normal(), 3) == logdensity(Normal(0,1), 3)
34+
@test Normal(2,4) == Normal=2, σ=4)
35+
@test Normal=4, μ=2) == Normal=2, σ=4)
36+
@test logdensity(Normal(), 3) == logdensity(Normal(0,1), 3)
3137
end
3238

3339
@testset "Kernel" begin

0 commit comments

Comments
 (0)