Skip to content

Commit 947e1f4

Browse files
committed
some tests
1 parent 00ac41e commit 947e1f4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/runtests.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using LinearAlgebra
66
using KeywordCalls
77
using Statistics
88

9+
910
function draw2(μ)
1011
x = rand(μ)
1112
y = rand(μ)
@@ -26,19 +27,40 @@ const sqrt2π = sqrt(2π)
2627
MeasureBase.logdensity(d::Normal{(:μ,:σ)}, x) = -log(d.σ) - (x - d.μ)^2 / (2 * d.σ^2)
2728
MeasureBase.logdensity(d::Normal{(:μ,)}, x) = - (x - d.μ)^2 / 2
2829
MeasureBase.logdensity(d::Normal{()}, x) = - x^2 / 2
29-
30+
3031
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{(:μ,:σ)}) = d.μ + d.σ * randn(rng, T)
3132
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{(:μ,)}) = d.μ + randn(rng, T)
3233
Base.rand(rng::Random.AbstractRNG, T::Type, d::Normal{()}) = randn(rng, T)
3334

35+
MeasureBase.representative(d::Normal{(:μ,:σ)}) = σ > 0.0 ? Lebesgue(ℝ) : Dirac(d.μ)
36+
MeasureBase.representative(d::Normal{(:μ,)}) = Lebesgue(ℝ)
37+
38+
# Leave this undefined to test fallback inference algorithm
39+
# MeasureBase.representative(::Normal) = Lebesgue(ℝ)
40+
3441
@test Normal(2,4) == Normal=2, σ=4)
3542
@test Normal=4, μ=2) == Normal=2, σ=4)
3643
@test logdensity(Normal(), 3) == logdensity(Normal(0,1), 3)
44+
45+
x = randn()
46+
@test_broken logdensity(Normal(3,2), Lebesgue(ℝ), x) logdensity(Normal(3,2), Normal(), x ) + logdensity(Normal(), Lebesgue(ℝ),x)
47+
@test_broken 𝒹(Normal(3,2), Normal())(x) logdensity(Normal(3,2), Normal(), x)
48+
end
49+
50+
@testset "Density" begin
51+
x = randn()
52+
f(x) = -x^2
53+
μ = Normal()
54+
ν = Lebesgue(ℝ)
55+
@test_broken 𝒹((f, μ), μ)(x) f(x)
56+
@test_broken logdensity((𝒹(μ, ν), ν), x) logdensity(μ, x)
3757
end
3858

59+
3960
@testset "Kernel" begin
40-
κ = MeasureBase.kernel(identity, MeasureBase.Dirac)
61+
κ = kernel(identity, Dirac)
4162
@test rand(κ(1.1)) == 1.1
63+
@test kernelize(Normal(0,1)) == (Kernel{Normal, UnionAll}(NamedTuple{(, ), T} where T<:Tuple), (0, 1))
4264
end
4365

4466
@testset "SpikeMixture" begin

0 commit comments

Comments
 (0)