Skip to content

Commit

Permalink
fix unit test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Oct 10, 2024
1 parent c93cbc3 commit 6557096
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
3 changes: 2 additions & 1 deletion EpiAware/src/EpiAwareUtils/EpiAwareUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Base: eltype
using Distributions, DocStringExtensions, QuadGK, Statistics, Turing

#Export Structures
export HalfNormal, DirectSample, SafePoisson, SafeNegativeBinomial
export HalfNormal, DirectSample, SafePoisson, SafeNegativeBinomial, RealValued,
RealUnivariateDistribution

#Export functions
export scan, spread_draws, censored_cdf, censored_pmf, get_param_array, prefix_submodel, ∫F
Expand Down
3 changes: 2 additions & 1 deletion EpiAware/src/EpiAwareUtils/RealValued.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Base.eltype(::Type{<:Distributions.Sampleable{F, RealValued}}) where {F} = Real
"""
A constant alias for `Distribution{Univariate, RealValued}`. This type represents a univariate distribution with real-valued outcomes.
"""
const RealUnivariateDistribution = Distributions.Distribution{Distributions.Univariate, RealValued}
const RealUnivariateDistribution = Distributions.Distribution{
Distributions.Univariate, RealValued}
2 changes: 1 addition & 1 deletion EpiAware/src/EpiAwareUtils/SafePoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function procf(λ, K, s::Float64)

if K < 10
px = -float(λ)
py = λ^K / factorial(K)
py = λ^K / factorial(floor(Int, K))
else
δ = 0.08333333333333333 / K
δ -= 4.8 * δ^3
Expand Down
12 changes: 3 additions & 9 deletions EpiAware/test/EpiAwareUtils/RealValued.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
@testitem "RealValued Type Tests" begin
@test RealValued <: Distributions.ValueSupport
end

# Test for eltype function
@testitem "eltype Function Tests" begin
using Distributions
struct DummySampleable <: Sampleable{Univariate, RealValued} end
@test eltype(DummySampleable) == Real
end

# Test for RealUnivariateDistribution alias
@testitem "RealUnivariateDistribution Alias Tests" begin
@test RealValued <: Distributions.ValueSupport
@test eltype(DummySampleable) == Real
@test RealUnivariateDistribution == Distribution{Univariate, RealValued}
end
2 changes: 1 addition & 1 deletion EpiAware/test/EpiAwareUtils/SafeNegativeBinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end

dist = SafeNegativeBinomial(r, p)
@testset "Large value of mean samples a BigInt with SafePoisson" begin
@test rand(dist) isa BigInt
@test rand(dist) isa Real
end
@testset "Large value of mean sample failure with Poisson" begin
_dist = EpiAware.EpiAwareUtils._negbin(dist)
Expand Down
8 changes: 4 additions & 4 deletions EpiAware/test/EpiAwareUtils/SafePoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
λ = 10.0
dist = SafePoisson(λ)
@test typeof(dist) <: SafePoisson
@test rand(dist) isa Int
@test rand(dist, 10) isa Vector{Int}
@test rand(dist, 10, 10) isa Array{Int}
@test rand(dist) isa Real
@test rand(dist, 10) isa Vector{Real}
@test rand(dist, 10, 10) isa Array{Real}
end

@testitem "Check distribution properties of SafePoisson" begin
Expand Down Expand Up @@ -54,7 +54,7 @@ end
bigλ = exp(48.0) #Large value of λ
dist = SafePoisson(bigλ)
@testset "Large value of mean samples a BigInt with SafePoisson" begin
@test rand(dist) isa BigInt
@test rand(dist) isa Real
end
@testset "Large value of mean sample failure with Poisson" begin
_dist = Poisson(dist.λ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ end

mdl = generate_observations(model, missing, 10)
draw = rand(mdl)
@test typeof(draw[:var"Test.y_t[1]"]) <: Int
@test typeof(draw[:var"Test.y_t[1]"]) <: Real
end

0 comments on commit 6557096

Please sign in to comment.