Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <[email protected]>
  • Loading branch information
quildtide and devmotion authored Sep 4, 2024
1 parent efc0a60 commit d13c8fb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
19 changes: 7 additions & 12 deletions test/testutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ end
function test_distr(distr::DiscreteUnivariateDistribution, n::Int;
testquan::Bool=true, rng::AbstractRNG=MersenneTwister(),
test_scalar_rand::Bool=false)
println(" testing $(distr)")
test_range(distr)
vs = get_evalsamples(distr, 0.00001)

Expand Down Expand Up @@ -73,9 +72,7 @@ end
# testing the implementation of a continuous univariate distribution
#
function test_distr(distr::ContinuousUnivariateDistribution, n::Int;
testquan::Bool=true, rng::AbstractRNG=MersenneTwister(123),
test_scalar_rand::Bool=false)
println(" testing $(distr)")
testquan::Bool=true, rng::AbstractRNG=MersenneTwister(123))
test_range(distr)
vs = get_evalsamples(distr, 0.01, 2000)

Expand Down Expand Up @@ -116,8 +113,7 @@ function test_samples(s::Sampleable{Univariate, Discrete}, # the sampleable
n::Int; # number of samples to generate
q::Float64=1.0e-7, # confidence interval, 1 - q as confidence
verbose::Bool=false, # show intermediate info (for debugging)
rng::Union{AbstractRNG, Missing}=missing, # add an rng?
call_scalar::Bool=false) # directly scall the scalar rand(d) instead
rng::Union{AbstractRNG, Missing}=missing) # add an rng?
# The basic idea
# ------------------
# Generate n samples, and count the occurrences of each value within a reasonable range.
Expand Down Expand Up @@ -211,8 +207,8 @@ function test_samples(s::Sampleable{Univariate, Discrete}, # the sampleable
end

test_samples(distr::DiscreteUnivariateDistribution, n::Int;
q::Float64=1.0e-6, verbose::Bool=false, rng=missing, kwargs...) =
test_samples(distr, distr, n; q=q, verbose=verbose, rng=rng, kwargs...)
q::Float64=1.0e-6, verbose::Bool=false, rng=missing) =
test_samples(distr, distr, n; q=q, verbose=verbose, rng=rng)

# for continuous samplers
#
Expand All @@ -222,8 +218,7 @@ function test_samples(s::Sampleable{Univariate, Continuous}, # the sampleable
nbins::Int=50, # divide the main interval into nbins
q::Float64=1.0e-6, # confidence interval, 1 - q as confidence
verbose::Bool=false, # show intermediate info (for debugging)
rng::Union{AbstractRNG, Missing}=missing, # add an rng?
call_scalar::Bool=false) # directly scall the scalar rand(d) instead
rng::Union{AbstractRNG, Missing}=missing) # add an rng?

# The basic idea
# ------------------
Expand Down Expand Up @@ -332,8 +327,8 @@ function test_samples(s::Sampleable{Univariate, Continuous}, # the sampleable
return samples
end

test_samples(distr::ContinuousUnivariateDistribution, n::Int; nbins::Int=50, q::Float64=1.0e-6, verbose::Bool=false, rng=missing, kwargs...) =
test_samples(distr, distr, n; nbins=nbins, q=q, verbose=verbose, rng=rng, kwargs...)
test_samples(distr::ContinuousUnivariateDistribution, n::Int; nbins::Int=50, q::Float64=1.0e-6, verbose::Bool=false, rng=missing) =
test_samples(distr, distr, n; nbins=nbins, q=q, verbose=verbose, rng=rng)


#### Testing range & support methods
Expand Down
2 changes: 1 addition & 1 deletion test/univariate/continuous/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test_cgf(Exponential(10 ), (0.08, -1, -100f0, -1e6))
Exponential(0.91),
Exponential(10)
]
test_distr(d, 10^6, test_scalar_rand = true)
test_distr(d, 10^6)
end
end
2 changes: 1 addition & 1 deletion test/univariate/continuous/logitnormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ end
LogitNormal(-2, 3),
LogitNormal(0, 0.2)
]
test_distr(d, 10^6, test_scalar_rand = true)
test_distr(d, 10^6)
end
end
2 changes: 1 addition & 1 deletion test/univariate/continuous/lognormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,6 @@ end
LogNormal(3.0, 1.0)
LogNormal(3.0, 2.0)
]
test_distr(d, 10^6, test_scalar_rand = true)
test_distr(d, 10^6)
end
end
2 changes: 1 addition & 1 deletion test/univariate/continuous/normalcanon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
NormalCanon(-1.0, 2.5)
NormalCanon(2.0, 0.8)
]
test_distr(d, 10^6, test_scalar_rand = true)
test_distr(d, 10^6)
end
end
2 changes: 1 addition & 1 deletion test/univariate/continuous/pareto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
Pareto(2.0, 1.5)
Pareto(3.0, 2.0)
]
test_distr(d, 10^6, test_scalar_rand = true)
test_distr(d, 10^6)
end
end

0 comments on commit d13c8fb

Please sign in to comment.