Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit testing get/set functionality to for protected parameters #1293

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ add_subdirectory(functional_testing/fire fates_fuel_ftest)
## Unit tests
add_subdirectory(unit_testing/fire_weather_test fates_fire_weather_utest)
add_subdirectory(unit_testing/fire_fuel_test fates_fire_fuel_utest)
add_subdirectory(unit_testing/parteh_test fates_parteh_utest)
5 changes: 5 additions & 0 deletions testing/unit_testing/parteh_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(pfunit_sources test_PRTAllometricCNP.pf)

add_pfunit_ctest(PRTAllometricCNP
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES fates csm_share)
103 changes: 103 additions & 0 deletions testing/unit_testing/parteh_test/test_PRTAllometricCNP.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module test_PRTAllometricCNP
!
! DESCRIPTION:
! Test the FATES PRTAllometricCNPMod subroutines
!
use funit
use FatesConstantsMod, only : r8 => fates_r8
use FatesConstantsMod, only : default_regeneration
use FatesConstantsMod, only : mm_per_cm
use FatesConstantsMod, only : min_max_dbh_for_trees
use PRTParametersMod, only : prt_params
use PRTGenericMod, only : store_organ
use PRTAllometricCNPMod, only : cnp_allom_prt_vartypes
use PRTAllometricCNPMod, only : stoich_growth_min
use PRTAllometricCNPMod, only : acnp_bc_inout_id_dbh
use PRTAllometricCNPMod, only : acnp_bc_in_id_pft
use PRTAllometricCNPMod, only : acnp_bc_in_id_nc_repro
use PRTAllometricCNPMod, only : acnp_bc_in_id_pc_repro

implicit none

@TestCase
type, extends(TestCase) :: TestPRTAllomCNP
type(cnp_allom_prt_vartypes) :: cnp_allom_prt
!contains
! procedure :: setUp
end type TestPRTAllomCNP

! assertEqual tolerance
real(r8), parameter :: tol = 1.e-13_r8

contains

!subroutine setUp(this)
! class(TestPRTAllomCNP), intent(inout) :: this
! ! Globals and parameters
!end subroutine setUp

@Test
subroutine EstimateGrowthNC_ReproBoundsCheck(this)

! Test that CN growth estimate passes if the C reproductive fraction is exactly one

class(TestPRTAllomCNP), intent(inout) :: this ! test object

!! Globals
! targets for associations
integer, parameter :: repro_id = 5 ! non-public parameter from PRTAllometricCNPMod
integer, parameter :: num_intgr_vars = 7
integer, target :: ipft = 1
real(r8), target :: dbh = 1._r8
real(r8), target :: nc_repro = 0._r8
real(r8), target :: pc_repro = 0._r8

!! subroutine arguments
! Dummy arguments, not used for repro_id case
real(r8) :: dummy_target_c(1) = 0._r8
real(r8) :: dummy_target_dcdd(1) = 0._r8

! Necessary arguments
logical :: state_mask(num_intgr_vars) = .false. ! state mask, intent(in)
real(r8) :: avg_nc ! Average N:C ratio, intent(out)
real(r8) :: avg_pc ! Average P:C ratio, intent(out)

! Initialize the prt_param type and values
allocate(prt_params%allom_dbh_maxheight(acnp_bc_in_id_pft))
allocate(prt_params%dbh_repro_threshold(acnp_bc_in_id_pft))
allocate(prt_params%seed_alloc(acnp_bc_in_id_pft))

prt_params%allom_dbh_maxheight(acnp_bc_in_id_pft) = 1000._r8 ! current default param
prt_params%dbh_repro_threshold(acnp_bc_in_id_pft) = 90._r8 ! current default param
prt_params%seed_alloc(acnp_bc_in_id_pft) = 1._r8 ! assigned to repro_c_frac

! Unused for repro check
allocate(prt_params%seed_alloc_mature(acnp_bc_in_id_pft))
allocate(prt_params%repro_alloc_b(acnp_bc_in_id_pft))
allocate(prt_params%repro_alloc_a(acnp_bc_in_id_pft))
allocate(prt_params%organ_param_id(1))
allocate(prt_params%nitr_stoich_p1(1,1))
allocate(prt_params%phos_stoich_p1(1,1))

! Manually initialize minimum necessary PRT vartype subtypes
allocate(this%cnp_allom_prt%bc_inout(acnp_bc_inout_id_dbh))
allocate(this%cnp_allom_prt%bc_in(acnp_bc_in_id_pc_repro))

this%cnp_allom_prt%bc_inout(acnp_bc_inout_id_dbh)%rval => dbh
this%cnp_allom_prt%bc_in(acnp_bc_in_id_pft)%ival => ipft
this%cnp_allom_prt%bc_in(acnp_bc_in_id_nc_repro)%rval => nc_repro
this%cnp_allom_prt%bc_in(acnp_bc_in_id_pc_repro)%rval => pc_repro

! only test the repro_id case
state_mask(repro_id) = .true.

call this%cnp_allom_prt%EstimateGrowthNC(dummy_target_c,dummy_target_dcdd, &
state_mask,avg_nc,avg_pc)

@assertEqual(avg_nc, 1._r8, tolerance=tol)
@assertEqual(avg_pc, 1._r8, tolerance=tol)

end subroutine EstimateGrowthNC_ReproBoundsCheck


end module test_PRTAllometricCNP
3 changes: 3 additions & 0 deletions testing/unit_tests.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ test_dir = fates_fire_weather_utest

[fire_fuel]
test_dir = fates_fire_fuel_utest

[parteh]
test_dir = fates_parteh_utest