Skip to content

test: modularize test suite, fix S7 checks, and add comprehensive coverage (PR 7)#22

Merged
Cidree merged 17 commits into
mainfrom
avv-tests-comprehensive
Jun 20, 2026
Merged

test: modularize test suite, fix S7 checks, and add comprehensive coverage (PR 7)#22
Cidree merged 17 commits into
mainfrom
avv-tests-comprehensive

Conversation

@aitorvv

@aitorvv aitorvv commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Description

This Pull Request implements PR 7 from the development roadmap: a modular and comprehensive test suite for cidree-silviculture.

  • Modularized the monolithic test suite (replacing test-dendrometry.R with dedicated files like test-stand-density.R, test-sample-size.R, etc.).
  • Fixed S7 object inspection checks using proper extraction logic (S7::prop()).
  • Corrected various package-level calculations and validation issues (e.g., dominant height diameter validation and basal area multipliers).
  • Calibrated test expectations for LiDAR metrics (lid_lhdi) and thinning functions.

Verification

devtools::load_all("cidree-silviculture")

# 1. Verify bugfix in LHDI diversity index precision:
lidar_heights <- c(1.1, 1.2, 1.3, 1.6, 1.7, 2.1, 2.2, 2.3)
lid_lhdi(lidar_heights) # Expected to run without warnings and return exactly: 0.7144

# 2. Verify Sample Size module (Stratified) doesn't abort with correct syntax:
df_dummy <- data.frame(
  strata_id = rep(c("A", "B"), each = 4),
  vol = c(10, 12, 15, 11, 20, 22, 25, 23),
  area = rep(c(5, 10), each = 4)
)
sample_strat <- silv_sample_size_stratified(
  data = df_dummy, x = vol, strata = strata_id, total_area = area, 
  plot_size = 500, method = "prop", quiet = TRUE
)
str(sample_strat) # Must return a data.frame with proportional sampling sizes

# 3. Verify Thinning Simulation object extraction via S7
df_plot <- inventory_samples |> 
  dplyr::filter(plot_id == 8) |>
  dplyr::count(species, dclass = silv_tree_dclass(diameter)) |>
  dplyr::mutate(ntrees_ha = silv_density_ntrees_ha(n, plot_size = 10))

thinning_result <- silv_treatment_thinning(
  df_plot, dclass, dclass, ntrees_ha, thinning = "below", perc = 0.3, .groups = "species"
)
names(S7::prop(thinning_result, "data")) # Must include: "ntrees_ha_extract", "ntrees_ha_remain"

aitorvv added 17 commits May 17, 2026 11:03
- Add rcd and bp parameters to silv_predict_biomass(); rcd defaults to
  diameter when not provided, bp defaults to NA_real_
- Replace model-specific dispatch (ruiz-peinado only) with universal
  calc_biomass() inner function using eval_env = list(d,h,rcd,bp);
  now all 7 allometric models work out of the box
- Add return_rmse / return_r2 handling inside calc_biomass()
- Fix eq_biomass_cudjoe_2024() returning equation = 'cudjoe-2017' instead
  of 'cudjoe-2024'

Documentation (Roxygen2):
- silv_predict_biomass(): add @param rcd/@param bp; @details lists all 7
  models with input-variable requirements (rcd/bp for menendez-2022)
- eq_biomass_ruiz_peinado_2011(): add explicit softwood species list (10)
  and component hierarchy (AGB/BGB -> structural groups -> components)
- eq_biomass_ruiz_peinado_2012(): add explicit hardwood species list (13)
  and component hierarchy; fix missing comma in @Seealso
- eq_biomass_dieguez_aranda_2009(): rewrite @details with consistent
  format; fix typo 'Pinaster radiata' -> 'Pinus radiata'
- eq_biomass_montero_2005(): replace 'There are 35 species' with explicit
  bulleted species list; add component hierarchy; fix @Seealso comma
- eq_biomass_manrique_2017(): rewrite @details in structured format; fix
  'thin branches' -> 'small branches' to match biomass_models column
- eq_biomass_menendez_2022(): correct species count 15 -> 18 + 3
  functional groups; add non-standard input note (rcd/bp)
- eq_biomass_cudjoe_2024(): rewrite @details in structured format; fix
  'brances' typo in component name

README.md:
- Add 'Suggested companion reading' section with poster DOI
  https://doi.org/10.13140/RG.2.2.28098.75205

inst/references.bib:
- Resolve unresolved merge conflict: keep menendez-2022 and cudjoe-2024
  entries (HEAD), discard palahi-2003 (other branch)
- Add poster BibTeX entry (vazquez-veloso_poster_2025)
…issing BGB and total tree components and update Roxygen2 docs
…s-lists

# Conflicts:
#	NAMESPACE
#	_pkgdown.yml
@Cidree Cidree merged commit a2cbab3 into main Jun 20, 2026
1 check passed
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.

2 participants