Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Apr 26, 2024
1 parent 1d8634f commit 853ed7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion core/src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function get_storages_from_levels(basin::Basin, levels::Vector)::Vector{Float64}

for (i, level) in enumerate(levels)
storage = get_storage_from_level(basin, i, level)
if isnan(storage)
bottom = first(basin.level[i])
node_id = basin.node_id.values[i]
if level < bottom
@error "The initial level ($level) of $node_id is below the bottom ($bottom)."
errors = true
end
storages[i] = storage
Expand Down
7 changes: 5 additions & 2 deletions core/test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ end
@test length(logger.logs) == 1
@test logger.logs[1].level == Error
@test logger.logs[1].message ==
"The level -1.0 of Basin #1 is lower than the bottom of this basin; 0.0."
"The initial level (-1.0) of Basin #1 is below the bottom (0.0)."

# Converting from storages to levels and back should return the same storages
storages = range(0.0, 2 * storage[end], 50)
levels = [Ribasim.get_area_and_level(basin, 1, s)[2] for s in storages]
storages_ = [Ribasim.get_storage_from_level(basin, 1, l) for l in levels]

@test storages storages_

# At or below bottom the storage is 0
@test Ribasim.get_storage_from_level(basin, 1, 0.0) == 0.0
@test Ribasim.get_storage_from_level(basin, 1, -1.0) == 0.0
end

@testitem "Expand logic_mapping" begin
Expand Down

0 comments on commit 853ed7c

Please sign in to comment.