Skip to content

Commit

Permalink
✅ fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
evadelmas committed Mar 23, 2020
1 parent 5990b05 commit 746eae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/measures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@ end
# Takes a simulation output as a mandatory argument. The two keyword arguments
# are `as` (can be `:json` or `:jld`), defining the file format, and `filename`
# (without an extension, defaults to `NaN`). If `:jld` is used, the variable
# is named `befwm_simul` unless a `varname` is given.
# is named `befwm_simul`.
#
# Called with the defaults, this function will write `befwm_xxxxxxxx.json`
# with the current simulation output, where `xxxxxxxx` is a hash of the `p`
# output (ensuring that all output files are unique).
#
# This function is *not* exported, so it must be called with `BioEnergeticFoodWebs.save`.
#
# """
function save(sim::Dict{Symbol,Any}; as::Symbol=:jld, filename=nothing, varname=nothing)
function save(sim::Dict{Symbol,Any}; as::Symbol=:jld, filename=nothing)
if as == :JSON
as = :json
end
Expand All @@ -154,15 +152,13 @@ function save(sim::Dict{Symbol,Any}; as::Symbol=:jld, filename=nothing, varname=
if filename == nothing
filename = "befwm_" * string(hash(sim))
end
if varname == nothing
varname = "befwm_simul"
end
if as == :json
sim[:p][:dc] = string(sim[:p][:dc])
sim[:p][:dp] = string(sim[:p][:dp])
befwm_simul = deepcopy(sim)
befwm_simul[:p][:dc] = string(befwm_simul[:p][:dc])
befwm_simul[:p][:dp] = string(befwm_simul[:p][:dp])
filename = filename * ".json"
f = open(filename, "w")
JSON.print(f, sim)
JSON.print(f, befwm_simul)
close(f)
end
if as == :jld
Expand Down
5 changes: 2 additions & 3 deletions test/measures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ module TestSave
# Test if the content is the same
@load def_fname sim
@test sim == s

rm(def_fname)

# Test is it works with as = :JLD
ext = :JLD
save(s, as = ext)
Expand All @@ -88,15 +88,14 @@ module TestSave

# Test with .json
ext = :json
save(s, as = ext)
fname = "befwm_" * string(hash(s)) * ".json"
save(s, as = ext)
@test isfile(fname)
rm(fname)

# Test with .JSON
ext = :JSON
save(s, as = ext)
fname = "befwm_" * string(hash(s)) * ".json"
@test isfile(fname)
rm(fname)

Expand Down

0 comments on commit 746eae1

Please sign in to comment.