Add tests for rootdepth_main & soilfluxes !freedrain; fix 3 source bugs in RootDepth.jl#1
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
|
@copilot 1. rootdepth_main还未测试;2. soilfluxes中if !freedrain # 非自由排水这种情景还未测试。 |
Done in bf917a8:
|
There was a problem hiding this comment.
Pull request overview
该 PR 旨在为此前未覆盖的 rootdepth_main 全流程与 soilfluxes 的 !freedrain 分支补齐测试,并在测试驱动下修复若干会导致运行时报错的实现问题,从而提高 RootDepth/SoilFluxes 相关模块的稳定性与可回归性。
Changes:
- 修复
RootDepth.jl中soilfluxes的freedrain关键字参数类型不匹配、以及循环外读取dθ的作用域问题,并移除/注释已删除的同位素相关变量引用。 - 修复
SoilFluxes.jl在部分边界条件下未显式设置k=2三对角系数、以及干燥限制中θ_cp字段引用错误。 - 新增/扩展测试用例,覆盖
extraction、updatewtd_shallow、soilfluxes(!freedrain)与rootdepth_main的关键路径,并更新总测试入口与 wtable 子测试入口。
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/RootDepth.jl |
修复 freedrain 传参类型、dθ 作用域与同位素残留引用导致的运行时错误。 |
src/SoilFluxes.jl |
补齐 k=2 系数设置以覆盖循环起点缺口;修正干燥限制中 θ_cp 取值字段。 |
src/extraction.jl |
修复向量 clamp 广播用法;避免 rootfc==0 时的除零风险。 |
test/runtests.jl |
将新增测试文件纳入总测试入口。 |
test/test_soil_parameters.jl |
按当前土壤参数结构体字段更新断言,并补充全土壤类型的基本合法性检查。 |
test/test_soil_fluxes.jl |
重构并新增 !freedrain 分支覆盖及自由/非自由排水对比测试。 |
test/test_extraction.jl |
新增 extraction 单元测试覆盖核心行为与边界情形。 |
test/test_updatewtd_shallow.jl |
新增 find_jwt/updatewtd_shallow/cal_factor 的单元测试。 |
test/test_rootdepth.jl |
新增 rootdepth_main 集成测试以覆盖全链路调用(含 !freedrain 集成)。 |
test/wtable/test-river.jl |
补充 using ASAP, Test 以确保独立运行该测试文件。 |
test/wtable/runtests.jl |
将新增的 river 测试纳入 wtable 测试入口。 |
| et_s_before = copy(args[33]) # et_s is the 33rd arg | ||
| result = rootdepth_main(args...) | ||
| @test result === nothing | ||
| # 所有输出应保持不变 | ||
| @test args[33] == et_s_before |
| et_s = args[33] | ||
| et_s_init = et_s[2, 2] |
| et_s = args[33] | ||
| et_c = args[35] | ||
| rech = args[30] |
| et_s = args[33] | ||
| et_c = args[35] |
| f1 = ASAP.cal_factor(-0.5, fdepth) | ||
| @test f1 ≈ 1.0 # clamped to 1.0 | ||
|
|
||
| # z = -3.5 (z + 1.5 = -1.0): factor = exp(-0.5) ≈ 0.607 |
|
@copilot 修复上述review comments |
Previously untested:
rootdepth_main(entirely) and the!freedrainbranch ofsoilfluxes. Running these paths exposed three bugs inRootDepth.jlthat caused runtime errors before any assertions could be checked.Bugs fixed in
RootDepth.jlfreedraintype mismatch —soilfluxesexpectsfreedrain::Boolbutrootdepth_mainpassesfreedrain::Intdirectly as a keyword arg; Julia does not auto-convert. Fixed withBool(freedrain).transpo18stepandupdated_o18(removed when isotope tracking was commented out fromsoilfluxes) causedUndefVarErroron any active vegetation cell. Commented out.dθscope bug —dθwas first assigned inside thefor itimeloop but read at line 260 outside it. Julia may not expose loop-internal variables in the enclosing scope. Fixed by pre-initializingdθ = zeros(Float64, nzg)before the loop.Tests added
test/test_rootdepth.jl— Four testsets: zero-landmask skip, water-body cell (veg=1), free-drain vegetation cell (veg=7), non-free-drain vegetation cell (veg=7). Exercises the full call chain includingextraction,soilfluxes, andupdatewtd_shallow.test/test_soil_fluxes.jl— Three new testsets for!freedrain:jwt≤2branch (water table below all layers),jwt>3branch (water table at a mid-layer), and a free vs. non-free-drain comparison verifyingrech=0for non-free-drain andrech<0for free-drain (negative = downward drainage).