1
1
# This file is a part of DensityInterface.jl, licensed under the MIT License (MIT).
2
2
3
3
"""
4
- DensityInterface.test_density_interface(d, x, ref_logd_at_x)
4
+ DensityInterface.test_density_interface(d, x, ref_logd_at_x; compare=isapprox, kwargs... )
5
5
6
6
Test if `d` is compatible with `DensityInterface`.
7
7
@@ -11,24 +11,28 @@ that the behavior of [`logdensityof(d)`](@ref),
11
11
12
12
Also tests if `logfuncdensity(logdensityof(d))` returns
13
13
a density equivalent to `d` in respect to the functions above.
14
+
15
+ The results of `logdensityof(d, x)` and `densityof(d, x)` are compared to
16
+ `ref_logd_at_x` and `exp(ref_logd_at_x)` using `compare`. `kwargs...` are
17
+ forwarded to `compare`.
14
18
"""
15
- function test_density_interface (d, x, ref_logd_at_x)
19
+ function test_density_interface (d, x, ref_logd_at_x; compare = isapprox, kwargs ... )
16
20
@testset " test_density_interface: $d with input $x " begin
17
21
ref_d_at_x = exp (ref_logd_at_x)
18
22
19
23
@test hasdensity (d) == true
20
- @test logdensityof (d, x) == ref_logd_at_x
24
+ @test compare ( logdensityof (d, x), ref_logd_at_x; kwargs ... )
21
25
log_f = logdensityof (d)
22
- @test log_f (x) == ref_logd_at_x
23
- @test densityof (d,x) == ref_d_at_x
24
- @test densityof (d)(x) == ref_d_at_x
26
+ @test compare ( log_f (x), ref_logd_at_x; kwargs ... )
27
+ @test compare ( densityof (d,x), ref_d_at_x; kwargs ... )
28
+ @test compare ( densityof (d)(x), ref_d_at_x; kwargs ... )
25
29
26
30
d2 = logfuncdensity (log_f)
27
31
@test hasdensity (d2) == true
28
- @test logdensityof (d2, x) == ref_logd_at_x
32
+ @test compare ( logdensityof (d2, x), ref_logd_at_x; kwargs ... )
29
33
log_f2 = logdensityof (d2)
30
- @test log_f2 (x) == ref_logd_at_x
31
- @test densityof (d2,x) == ref_d_at_x
32
- @test densityof (d2)(x) == ref_d_at_x
34
+ @test compare ( log_f2 (x), ref_logd_at_x; kwargs ... )
35
+ @test compare ( densityof (d2,x), ref_d_at_x; kwargs ... )
36
+ @test compare ( densityof (d2)(x), ref_d_at_x; kwargs ... )
33
37
end
34
38
end
0 commit comments