Skip to content

Add tests for rootdepth_main & soilfluxes !freedrain; fix 3 source bugs in RootDepth.jl#1

Merged
kongdd merged 3 commits into
mainfrom
copilot/add-tests-for-julia-module
May 31, 2026
Merged

Add tests for rootdepth_main & soilfluxes !freedrain; fix 3 source bugs in RootDepth.jl#1
kongdd merged 3 commits into
mainfrom
copilot/add-tests-for-julia-module

Conversation

Copy link
Copy Markdown

Copilot AI commented May 31, 2026

Previously untested: rootdepth_main (entirely) and the !freedrain branch of soilfluxes. Running these paths exposed three bugs in RootDepth.jl that caused runtime errors before any assertions could be checked.

Bugs fixed in RootDepth.jl

  • freedrain type mismatchsoilfluxes expects freedrain::Bool but rootdepth_main passes freedrain::Int directly as a keyword arg; Julia does not auto-convert. Fixed with Bool(freedrain).
  • Undefined isotope variables — Lines referencing transpo18step and updated_o18 (removed when isotope tracking was commented out from soilfluxes) caused UndefVarError on any active vegetation cell. Commented out.
  • scope bug was first assigned inside the for itime loop but read at line 260 outside it. Julia may not expose loop-internal variables in the enclosing scope. Fixed by pre-initializing dθ = 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 including extraction, soilfluxes, and updatewtd_shallow.
  • test/test_soil_fluxes.jl — Three new testsets for !freedrain: jwt≤2 branch (water table below all layers), jwt>3 branch (water table at a mid-layer), and a free vs. non-free-drain comparison verifying rech=0 for non-free-drain and rech<0 for free-drain (negative = downward drainage).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

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 ☂️

@kongdd
Copy link
Copy Markdown
Member

kongdd commented May 31, 2026

@copilot 1. rootdepth_main还未测试;2. soilfluxes中if !freedrain # 非自由排水这种情景还未测试。

Copy link
Copy Markdown
Author

Copilot AI commented May 31, 2026

@copilot 1. rootdepth_main还未测试;2. soilfluxes中if !freedrain # 非自由排水这种情景还未测试。

Done in bf917a8:

  1. rootdepth_main tests — added test/test_rootdepth.jl with four testsets: zero-landmask skip, water-body cell (veg=1), free-drain vegetation cell, and non-free-drain vegetation cell. Also fixed three bugs in RootDepth.jl that blocked active-cell execution (undefined transpo18step/updated_o18 variables; freedrain::IntBool mismatch in soilfluxes call).

  2. !freedrain (非自由排水) tests — added three new testsets in test_soil_fluxes.jl: jwt≤2 branch (water table below all layers), jwt>3 branch (water table in a middle layer), and a free vs non-free-drain comparison verifying that rech=0.0 for non-free-drain and rech<0 for free-drain (downward drainage sign convention).

Copilot AI changed the title Add comprehensive tests for Julia-translated modules; fix 4 source bugs blocking test execution Add comprehensive tests for Julia-translated modules; fix 6 source bugs blocking test execution May 31, 2026
Copilot finished work on behalf of kongdd May 31, 2026 06:45
Copilot AI requested a review from kongdd May 31, 2026 06:45
Copilot AI changed the title Add comprehensive tests for Julia-translated modules; fix 6 source bugs blocking test execution Add tests for rootdepth_main & soilfluxes !freedrain; fix 3 source bugs in RootDepth.jl May 31, 2026
Copilot finished work on behalf of kongdd May 31, 2026 07:00
@kongdd kongdd marked this pull request as ready for review May 31, 2026 07:07
Copilot AI review requested due to automatic review settings May 31, 2026 07:07
@kongdd kongdd merged commit b8aa4a0 into main May 31, 2026
4 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在为此前未覆盖的 rootdepth_main 全流程与 soilfluxes!freedrain 分支补齐测试,并在测试驱动下修复若干会导致运行时报错的实现问题,从而提高 RootDepth/SoilFluxes 相关模块的稳定性与可回归性。

Changes:

  • 修复 RootDepth.jlsoilfluxesfreedrain 关键字参数类型不匹配、以及循环外读取 的作用域问题,并移除/注释已删除的同位素相关变量引用。
  • 修复 SoilFluxes.jl 在部分边界条件下未显式设置 k=2 三对角系数、以及干燥限制中 θ_cp 字段引用错误。
  • 新增/扩展测试用例,覆盖 extractionupdatewtd_shallowsoilfluxes(!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 传参类型、 作用域与同位素残留引用导致的运行时错误。
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 测试入口。

Comment thread test/test_rootdepth.jl
Comment on lines +97 to +101
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
Comment thread test/test_rootdepth.jl
Comment on lines +107 to +108
et_s = args[33]
et_s_init = et_s[2, 2]
Comment thread test/test_rootdepth.jl
Comment on lines +119 to +121
et_s = args[33]
et_c = args[35]
rech = args[30]
Comment thread test/test_rootdepth.jl
Comment on lines +134 to +135
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
@kongdd
Copy link
Copy Markdown
Member

kongdd commented May 31, 2026

@copilot 修复上述review comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants