Commit f83e15b1 authored by Victor Boussange's avatar Victor Boussange
Browse files

Adding many unit test files

parent 7208248f
......@@ -23,9 +23,9 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[CompilerSupportLibraries_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "ff8101d6736414bc93c0f8df77b1e4095ca988c3"
git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612"
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.3.2+0"
version = "0.3.3+0"
[[DataAPI]]
git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
......
cd(@__DIR__)
using Random;Random.seed!(0)
using JLD2
using Revise,ABMEv,Test
import ABMEv:update_rates_std!
a = 0;
sigma_K = .9;
sigma_a = .7;
......@@ -17,24 +23,25 @@ p_default = Dict(
na_init = K0
world0 = new_world_G(na_init,p_default,spread = .01)
worldall,p_default["tspan"] = runWorld_store_G(p_default,world0)
world_alive = collect(skipmissing(world0))
world_alive_test = collect(skipmissing(worldall[:,end]))
# @save "gillepsie_test.jld2" world_alive
@load "gillepsie_test.jld2" world_alive
## Testing
@testset "testing global functioning" begin
@test size(worldall,2) > 1
@test p_default["tspan"][end] >= p_default["tend"]
end
## Comparing simulation
xarray = get_xarray(world_alive,1);xarray_test = get_xarray(world_alive_test,1);
@test xarray xarray_test
@testset "testing update rates matrix" begin
bs_end = get_b.(world_alive);ds_end = get_d.(world_alive)
update_rates_std!(world_alive,p_default,0.);
bs_recalculated = get_b.(world_alive);ds_recalculated = get_d.(world_alive);
@testset "birth coefficient" begin
for i in 1:length(bs_end)
@test bs_end[i] bs_recalculated[i];
end
end
@testset "death coefficient" begin
for i in 1:length(bs_end)
@test ds_end[i] ds_recalculated[i];
end
end
@test bs_end bs_recalculated;
@test ds_end ds_recalculated;
end
## Testing parallel implementation
using Random;Random.seed!(0)
cd(@__DIR__)
using Distributed;addprocs(exeflags="--project")
using Test
@everywhere begin
using ABMEv
sigma_a = 1.251;
K0 = 1000;
K(X) = 1 - 0.125 * sum(X.^2)
α(X,Y) = gaussian(X[1],Y[1],sigma_a)/K0
end
p = Dict(
"alpha" => α,
"K" => K,
"D" => [1e-2],
"mu" => [.1],
"tend" => 10.)
na_init = K0
agents = [Agent( [1e-2] .* randn(1) .- .5) for i in 1:K0]
# @test nprocs() == 5
# time should be less than 1 sec on the second run
# using BenchmarkTools
@time (worldall_test,p["tspan"]) = runWorld_store_WF(p,agents,reflected=false)
@test size(worldall_test,2) == 10
## load to compare simulation
# using JLD2
# @save "wrightfisher_test.jld2" worldall p
# @load "wrightfisher_test.jld2" worldall
# xarray = get_xarray(worldall,1); xarray_test = get_xarray(worldall_test,1)
# @test xarray ≈ xarray_test
......@@ -55,3 +55,27 @@ import ABMEv:update_rates_std!,updateWorld_G!
@btime updateWorld_G!(world0,p_default,update_rates_std!,tspan,true)
@btime update_afterbirth_std!(skipmissing(world0),1,p_default)
@btime update_afterdeath_std!(skipmissing(world0),[].8],p_default)
## parallelisation Gillepsie
# For now Gillepsie can not really be parallelised
using Distributed;addprocs(exeflags="--project")
@everywhere begin
using ABMEv
sigma_a = 1.251;
K0 = 1000;
K(X) = 1 - 0.125 * sum(X.^2)
α(X,Y) = gaussian(X[1],Y[1],sigma_a)/K0
end
p = Dict(
"alpha" => α,
"K" => K,
"D" => [1e-2],
"mu" => [.1],
"tend" => 10.,
"NMax" => Int(10000))
na_init = K0
world0 = new_world_G(na_init,p,spread = .01, offset = -.25)
tspan=zeros(1)
# using BenchmarkTools
# update_afterbirth_std!(skipmissing(world0),1,p)
# @btime update_afterdeath_std!(skipmissing(world0),[.8],p_default)
using Random;Random.seed!(0)
using Test
cd(@__DIR__)
using Revise,ABMEv
## 1D Simulation
a = 0;
sigma_K = .9;
sigma_a = 1.251;
......@@ -8,19 +12,20 @@ K0 = 1000;
K(X) = 1 - 0.125 * sum(X.^2)
α(X,Y) = gaussian(X[1],Y[1],sigma_a)/K0
# α(X,Y) = 0.
p_default = Dict(
p = Dict(
"alpha" => α,
"K" => K,
"D" => [1e-2],
"mu" => [.1],
"tend" => 1000.)
"tend" => 10.)
na_init = K0
agents = [Agent( [1e-2] .* randn(1) .- .5) for i in 1:K0]
@time worldall,p_default["tspan"] = runWorld_store_WF(p_default,agents,reflected=false);
# ======================================================================
@time worldall_test,p["tspan"] = runWorld_store_WF(p,agents,reflected=false);
## load to compare simulation
using JLD2
@save "wrightfisher_test.jld2" worldall p_default
using Plots
Plots.plot(worldall,p_default,what = ["var"])
# @save "wrightfisher_test.jld2" worldall p
@load "wrightfisher_test.jld2" worldall
xarray = get_xarray(worldall,1); xarray_test = get_xarray(worldall_test,1)
var(agents)
@test xarray xarray_test
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment