Skip to content

Commit

Permalink
estimate_PotNatVeg_composition() test cases for #218 and #219
Browse files Browse the repository at this point in the history
- new tests that #218 and #219 are resolved

- current new version of `estimate_PotNatVeg_composition()` does not show #218 but fails with test for #219
  • Loading branch information
dschlaep committed Nov 10, 2022
1 parent f1d18a3 commit 448a954
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/testthat/test_Vegetation.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,32 @@ test_that("Vegetation: estimate land cover composition", {
)
}


# issue 218: correction to C4 grass cover was not carried out as documented
# without C4 correction, C4 grass cover was 0.1166967
res_wo218 <- estimate_PotNatVeg_composition(
MAP_mm = 10 * clim[["MAP_cm"]],
MAT_C = 15,
mean_monthly_ppt_mm = 10 * clim[["meanMonthlyPPTcm"]],
mean_monthly_Temp_C = 5 + clim[["meanMonthlyTempC"]],
dailyC4vars = NULL
)
expect_gt(res_wo218[["Rel_Abundance_L0"]][["Grasses_C4"]], 0)

res_w218 <- estimate_PotNatVeg_composition(
MAP_mm = 10 * clim[["MAP_cm"]],
MAT_C = 15,
mean_monthly_ppt_mm = 10 * clim[["meanMonthlyPPTcm"]],
mean_monthly_Temp_C = 5 + clim[["meanMonthlyTempC"]],
dailyC4vars = c(
Month7th_NSadj_MinTemp_C = 5,
LengthFreezeFreeGrowingPeriod_NSadj_Days = 150,
DegreeDaysAbove65F_NSadj_DaysC = 110
)
)
expect_equal(res_w218[["Rel_Abundance_L0"]][["Grasses_C4"]], 0)


#--- The function `estimate_PotNatVeg_composition` can fail under a few
# situations:
# (i) fixed sum is more than 1
Expand All @@ -231,6 +257,23 @@ test_that("Vegetation: estimate land cover composition", {
)
)

# issue 219: output incorrectly contained negative cover
# if fixed `SumGrasses_Fraction` caused that other fixed cover summed > 1
# correct behavior is error
expect_error(
estimate_PotNatVeg_composition(
MAP_mm = 10 * clim[["MAP_cm"]],
MAT_C = clim[["MAT_C"]],
mean_monthly_ppt_mm = 10 * clim[["meanMonthlyPPTcm"]],
mean_monthly_Temp_C = clim[["meanMonthlyTempC"]],
dailyC4vars = clim[["dailyC4vars"]],
fix_shrubs = TRUE,
Shrubs_Fraction = 0.5,
fix_sumgrasses = TRUE,
SumGrasses_Fraction = 0.7
)
)

# (ii) all fixed but sum is less than 1 and !fill_empty_with_BareGround
expect_error(
estimate_PotNatVeg_composition(
Expand Down

0 comments on commit 448a954

Please sign in to comment.