Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Dec 16, 2024
1 parent 1a86893 commit d217094
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,28 @@ end
@test all(isapprox.(Δinf[1:2:end], 25.0; atol = 1e-10))
@test all(Δinf[2:2:end] .== 0.0)
end

@testitem "two_basin" begin
using DataFrames: DataFrame, nrow
using Dates: DateTime
import BasicModelInterface as BMI

toml_path = normpath(@__DIR__, "../../generated_testmodels/two_basin/ribasim.toml")
model = Ribasim.run(toml_path)
df = DataFrame(Ribasim.subgrid_level_table(model))

ntime = 367
@test nrow(df) == ntime * 2
@test df.subgrid_id == repeat(1:2; outer = ntime)
@test extrema(df.time) == (DateTime(2020), DateTime(2021))
@test all(df.subgrid_level[1:2] .== 0.01)

# After a month the h(h) of subgrid_id 2 increases by a meter
i_change = searchsortedfirst(df.time, DateTime(2020, 2))
@test df.subgrid_level[i_change + 1] - df.subgrid_level[i_change - 1] 1.0f0

# Besides the 1 meter shift the h(h) relations are 1:1
basin_level = copy(BMI.get_value_ptr(model, "basin.level"))
basin_level[2] += 1
@test basin_level df.subgrid_level[(end - 1):end]
end

0 comments on commit d217094

Please sign in to comment.