Skip to content

Commit

Permalink
Add sugar to extract_last_timesteps()
Browse files Browse the repository at this point in the history
  • Loading branch information
alaindanet authored and iago-lito committed Feb 21, 2023
1 parent 9a44039 commit 13b5662
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions test/measures/test-functioning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ end
sim_zero = simulates(params, [0, 0]; verbose = false)

# Total biomass should converge to K
@test biomass(sim_one_sp; last = 1).total
get_parameters(sim_one_sp).environment.K[2] rtol = 0.001
@test biomass(sim_one_sp; last = 1).total get_parameters(sim_one_sp).environment.K[2] rtol =
0.001

# Species sub selection works
@test biomass(sim_one_sp; last = 1, idxs = [1]).sp[1]
Expand All @@ -73,30 +73,36 @@ end
# Other hill diversity numbers
## Shannon
@test shannon_diversity(sim_two_sp[:, end]) ==
shannon_diversity(sim_two_sp; last = 1) == log(2)
shannon_diversity(sim_two_sp; last = 1) ==
log(2)

@test shannon_diversity(sim_one_sp[:, end]) ==
shannon_diversity(sim_one_sp; last = 1) 0.0 # 0 entropy if 1 species only
shannon_diversity(sim_one_sp; last = 1)
0.0 # 0 entropy if 1 species only

@test isnan(shannon_diversity(sim_zero[:, end])) ==
isnan(shannon_diversity(sim_zero; last = 1)) # Not defined for 0 species
isnan(shannon_diversity(sim_zero; last = 1)) # Not defined for 0 species

@test shannon_diversity(sim_one_sp[:, end]) ==
shannon_diversity(sim_one_sp; last = 1)
0.0 # 0 entropy if 1 species only

@test isnan(shannon_diversity(sim_zero[:, end])) ==
isnan(shannon_diversity(sim_zero; last = 1)) # Not defined for 0 species

## Simpson
@test simpson(sim_two_sp[:, end]) ==
simpson(sim_two_sp; last = 1) ==
1 / sum(2 .^ [1 / 2, 1 / 2])
@test simpson(sim_one_sp[:, end]) ==
simpson(sim_one_sp; last = 1) ==
1 / sum(2 .^ 1) == 0.5# 0.5 if 1 species only
@test isnan(simpson(sim_zero[:, end])) ==
isnan(simpson(sim_zero; last = 1)) # Not defined for 0 species
1 / sum(2 .^ 1) ==
0.5# 0.5 if 1 species only
@test isnan(simpson(sim_zero[:, end])) == isnan(simpson(sim_zero; last = 1)) # Not defined for 0 species

# Community evenness
@test evenness(sim_two_sp[:, end]) ==
evenness(sim_two_sp; last = 1) 1.0 # Maximum equity of species biomass
@test isnan(evenness(sim_one_sp[:, end])) ==
isnan(evenness(sim_one_sp; last = 1))# Should be NaN if 1 species
@test isnan(evenness(sim_zero[:, end])) ==
isnan(evenness(sim_zero; last = 1))# Should be NaN if 0 species
@test evenness(sim_two_sp[:, end]) == evenness(sim_two_sp; last = 1) 1.0 # Maximum equity of species biomass
@test isnan(evenness(sim_one_sp[:, end])) == isnan(evenness(sim_one_sp; last = 1))# Should be NaN if 1 species
@test isnan(evenness(sim_zero[:, end])) == isnan(evenness(sim_zero; last = 1))# Should be NaN if 0 species

end

0 comments on commit 13b5662

Please sign in to comment.