diff --git a/test/Test.jl b/test/Test.jl new file mode 100644 index 00000000..5a384d8d --- /dev/null +++ b/test/Test.jl @@ -0,0 +1,3 @@ +module Test + +end diff --git a/test/TestDeSolvers.jl b/test/TestDeSolvers.jl index 06b82de4..85a29291 100644 --- a/test/TestDeSolvers.jl +++ b/test/TestDeSolvers.jl @@ -1,5 +1,5 @@ ######################################################################################################################## -module RunTest +module TestDeSolvers ######################################################################################################################## ######################################################################################################################## # imports and exports @@ -7,28 +7,39 @@ using DataAssimilationBenchmarks.DeSolvers using DataAssimilationBenchmarks.L96 using Test +export sumfunc ######################################################################################################################## ######################################################################################################################## # first testset using Euler Maruyama -@testset "Euler Maruyama" begin +function sumfunc() # initial conditions and arguments x = zeros(40) + # step size h = 0.01 + F = 8.0 + + dx_params = Dict{String, Array{Float64}}("F" => [F]) # forcing parameter - f = 8.0 + kwargs = Dict{String, Any}( "h" => h, "diffusion" => 0.0, - "dx_params" => [f], + "dx_params" => dx_params, "dx_dt" => L96.dx_dt, ) + # parameters to test # em_step! writes over x in place em_step!(x, 0.0, kwargs) + # evaluate test pass/fail if the vector of x is equal to (f*h) in every instance - @test sum(x .== (f*h)) == 40 - # if conditions are true, pass + if sum(x .== (F*h)) == 40 + sumresult = true + else + sumresult = false + end + end ######################################################################################################################## diff --git a/test/TestTimeSeriesGeneration.jl b/test/TestTimeSeriesGeneration.jl index 68310656..77f64aa4 100644 --- a/test/TestTimeSeriesGeneration.jl +++ b/test/TestTimeSeriesGeneration.jl @@ -6,93 +6,97 @@ using DataAssimilationBenchmarks.DeSolvers using DataAssimilationBenchmarks.L96 using JLD using Random - ####################################################################################################################### # Test generation of the L96 model time series - +function testL96() # define the model and the solver -dx_dt = L96.dx_dt -step_model! = DeSolvers.em_step! + dx_dt = L96.dx_dt + step_model! = DeSolvers.em_step! # set model and experimental parameters -F = 8.0 -h = 0.001 -nanl = 1000 -sys_dim = 40 -diffusion = 0.1 -tanl = 0.01 -seed = 0 -Random.seed!(seed) + F = 8.0 + h = 0.001 + nanl = 1000 + sys_dim = 40 + diffusion = 0.1 + tanl = 0.01 + seed = 0 + Random.seed!(seed) # define the dx_params dict -dx_params = Dict{String, Array{Float64}}("F" => [F]) -fore_steps = convert(Int64, tanl/h) + dx_params = Dict{String, Array{Float64}}("F" => [F]) + fore_steps = convert(Int64, tanl/h) # set the kwargs for the integration scheme -kwargs = Dict{String, Any}( - "h" => h, - "diffusion" => diffusion, - "dx_params" => dx_params, - "dx_dt" => L96.dx_dt, - ) + kwargs = Dict{String, Any}( + "h" => h, + "diffusion" => diffusion, + "dx_params" => dx_params, + "dx_dt" => L96.dx_dt, + ) # set arbitrary initial condition -xt = ones(sys_dim) + xt = ones(sys_dim) # pre-allocate storage for the time series observations -tobs = Array{Float64}(undef,sys_dim, nanl) + tobs = Array{Float64}(undef,sys_dim, nanl) # loop the experiment, taking observations at time length tanl -for i in 1:nanl - for j in 1:fore_steps - step_model!(xt, 0.0, kwargs) + for i in 1:nanl + for j in 1:fore_steps + step_model!(xt, 0.0, kwargs) + end + tobs[:,i] = xt end - tobs[:,i] = xt -end # define the file name for the experiment output # dynamically based on experiment parameters -fname = "time_series_data_seed_" * lpad(seed, 4, "0") * - "_dim_" * lpad(sys_dim, 2, "0") * - "_diff_" * rpad(diffusion, 5, "0") * - "_F_" * lpad(F, 4, "0") * - "_tanl_" * rpad(tanl, 4, "0") * - "_nanl_" * lpad(nanl, 5, "0") * - "_h_" * rpad(h, 5, "0") * - ".jld" + fname = "time_series_data_seed_" * lpad(seed, 4, "0") * + "_dim_" * lpad(sys_dim, 2, "0") * + "_diff_" * rpad(diffusion, 5, "0") * + "_F_" * lpad(F, 4, "0") * + "_tanl_" * rpad(tanl, 4, "0") * + "_nanl_" * lpad(nanl, 5, "0") * + "_h_" * rpad(h, 5, "0") * + ".jld" # define the experimental data in a dictionary to write with JLD -data = Dict{String, Any}( - "h" => h, - "diffusion" => diffusion, - "F" => F, - "tanl" => tanl, - "nanl" => nanl, - "sys_dim" => sys_dim, - "tobs" => tobs - ) -path = "../data/time_series/" - + data = Dict{String, Any}( + "h" => h, + "diffusion" => diffusion, + "F" => F, + "tanl" => tanl, + "nanl" => nanl, + "sys_dim" => sys_dim, + "tobs" => tobs + ) + path = "../data/time_series/" # test to see if the data can be written to standard output directory -try - save(path * fname, data) - did_write = true -catch - # if not, set test case false - did_write = false -end - + function write_file() + try + save(path * fname, data) + did_write = true + catch + # if not, set test case false + did_write = false + end + end # test to see if the data can be read from standard output directory -try - tmp = load(path * fname) - did_read = true -catch - # if not, set test case false - did_read = false -end + function load_file() + try + tmp = load(path * fname) + did_read = true + catch + # if not, set test case false + did_read = false + end + end +write_file() +load_file() +end ####################################################################################################################### diff --git a/test/runtests.jl b/test/runtests.jl index 86bb7bd3..0f3865c7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,33 +9,22 @@ using JLD using Random using Test -######################################################################################################################## -######################################################################################################################## -# first testset using Euler Maruyama -@testset "Euler Maruyama" begin - # initial conditions and arguments - x = zeros(40) - - # step size - h = 0.01 - - # forcing parameter - f = 8.0 - kwargs = Dict{String, Any}( - "h" => h, - "diffusion" => 0.0, - "dx_params" => [f], - "dx_dt" => L96.dx_dt, - ) +# include statements and import statements +include("TestDeSolvers.jl") +import .TestDeSolvers +import .L96 - # parameters to test - # em_step! writes over x in place - em_step!(x, 0.0, kwargs) +include("TestTimeSeriesGeneration.jl") +import .TestDeSolvers +import .L96 - # evaluate test pass/fail if the vector of x is equal to (f*h) in every instance - @test sum(x .== (f*h)) == 40 +# test case 1: TestDeSolvers +@testset "Euler Maruyama" begin + @test TestDeSolvers.sumfunc() end -######################################################################################################################## - +# test case 2: TestTimeSeriesGeneration +@testset "Time Series" begin + @test TestTimeSeriesGeneration.testL96() +end end