11# This file is a part of DensityInterface.jl, licensed under the MIT License (MIT).
22
33"""
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... )
55
66Test if `d` is compatible with `DensityInterface`.
77
@@ -11,24 +11,28 @@ that the behavior of [`logdensityof(d)`](@ref),
1111
1212Also tests if `logfuncdensity(logdensityof(d))` returns
1313a 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`.
1418"""
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 ... )
1620 @testset " test_density_interface: $d with input $x " begin
1721 ref_d_at_x = exp (ref_logd_at_x)
1822
1923 @test hasdensity (d) == true
20- @test logdensityof (d, x) == ref_logd_at_x
24+ @test compare ( logdensityof (d, x), ref_logd_at_x; kwargs ... )
2125 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 ... )
2529
2630 d2 = logfuncdensity (log_f)
2731 @test hasdensity (d2) == true
28- @test logdensityof (d2, x) == ref_logd_at_x
32+ @test compare ( logdensityof (d2, x), ref_logd_at_x; kwargs ... )
2933 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 ... )
3337 end
3438end
0 commit comments