Skip to content

Commit

Permalink
start adding tests for template construction
Browse files Browse the repository at this point in the history
move tests
  • Loading branch information
cgarling committed Jun 26, 2024
1 parent 9462b55 commit c45e31e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ const rtols = (1e-3, 1e-7) # Relative tolerance levels to use for the above floa
end
end
end

@safetestset "Template Construction" include("templates/template_test.jl")

# Benchmarking
# let x=[1.0], M=[Float64[0 0 0; 0 0 0; 1 1 1]], N=Int64[0 0 0; 0 0 0; 3 3 3], C=zeros(3,3), G=[1.0]
Expand Down
41 changes: 41 additions & 0 deletions test/templates/template_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Distributions: Normal, ContinuousUnivariateDistribution
import Distributions: pdf
using Test
using StarFormationHistories: mini_spacing, dispatch_imf, mean


@testset "mini_spacing" begin
result = mini_spacing([0.08, 0.10, 0.12, 0.14, 0.16],
[1.0, 0.99, 0.98, 0.97, 0.96],
[13.545, 12.899, 12.355, 11.459, 10.947],
0.1, false)
@test result isa Vector{Float64}
@test length(result) > 5
@test maximum(diff(result)) < 0.1
result, spacing = mini_spacing([0.08, 0.10, 0.12, 0.14, 0.16],
[1.0, 0.99, 0.98, 0.97, 0.96],
[13.545, 12.899, 12.355, 11.459, 10.947],
0.1, true)
@test spacing isa Vector{Float64}
@test spacing diff(result)
end

# Make a test type that is a duplicate of Normal
struct TestType{T,S} <: ContinuousUnivariateDistribution # Distribution{Univariate, Continuous}
μ::T
σ::S
end
pdf(d::TestType, x::Real) = pdf(Normal(d.μ, d.σ), x)
Base.extrema(d::TestType) = (-Inf, Inf)

@testset "dispatch_imf" begin
@test dispatch_imf(TestType(0.0,1.0), 1.0) == pdf(Normal(0.0,1.0), 1.0)
testfunc(x) = x^2
@test dispatch_imf(testfunc, 2.0) == 4.0
testdist = Normal(0.0, 1.0)
@test dispatch_imf(testdist, 1.0) == pdf(testdist, 1.0)
end

@testset "mean" begin
@test mean(TestType(1.0,1.0)) mean(Normal(1.0,1.0))
end

0 comments on commit c45e31e

Please sign in to comment.