Skip to content

Commit

Permalink
piecewise added
Browse files Browse the repository at this point in the history
  • Loading branch information
ivborissov committed Mar 4, 2024
1 parent 06c3e21 commit f29f93f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/HetaSimulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module HetaSimulator
include("import_platform.jl")
include("gsa.jl")
include("save_as_heta.jl")
include("heta_funcs.jl")

heta_update()

Expand All @@ -78,4 +79,5 @@ module HetaSimulator
export gsa, pearson, partial, standard
export save_as_heta
export scale_params, unscale_params
export piecewise
end
15 changes: 15 additions & 0 deletions src/heta_funcs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
piecewise(args...) = begin
len = length(args)
res = for i in 1:div(len, 2)
if args[2*i]
return args[2*i-1]
end
end
if !isnothing(res)
return res
elseif mod(len, 2) === 1
return args[len]
else
return NaN
end
end
7 changes: 7 additions & 0 deletions test/heta_funcs_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@test piecewise(1, true, 2, false, 3, false, 100) === 1
@test piecewise(1, false, 2, true, 3, false, 100) === 2
@test piecewise(1, true, 100) === 1
@test piecewise(1, false, 100) === 100
@test piecewise(1, false) === NaN
@test piecewise(100) == 100
@test piecewise() === NaN
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ end

@testset "HetaSimulator" begin
@testset "Single-compartment model without events" begin include("single_comp_test.jl") end
@testset "Functions used in heta models" begin include("heta_funcs_test.jl") end
end

0 comments on commit f29f93f

Please sign in to comment.