Skip to content

Commit

Permalink
Merge pull request #34 from Space-Systems/add-more-unittests
Browse files Browse the repository at this point in the history
Add more pf unittests
  • Loading branch information
danlueck authored Dec 20, 2023
2 parents b52b334 + 327a005 commit 8104164
Show file tree
Hide file tree
Showing 11 changed files with 946 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: LD_LIBRARY_PATH=${{github.workspace}}/lib ctest -C ${{env.BUILD_TYPE}}
run: LD_LIBRARY_PATH=${{github.workspace}}/lib ctest -C ${{env.BUILD_TYPE}} --verbose
36 changes: 34 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,40 @@ add_pfunit_ctest (atmosphere_tests_nrlmsis00
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (atmosphere_tests_JB2008
TEST_SOURCES test_atmosphere_JB2008.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)
add_pfunit_ctest (atmosphere_tests_Exponential
TEST_SOURCES test_atmosphere_Exponential.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)
add_pfunit_ctest (solarsystem_tests
TEST_SOURCES test_solarsystem.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (Thirdbody_tests
TEST_SOURCES test_thirdbody.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (Radiation_tests
TEST_SOURCES test_radiation.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (gravity_tests
TEST_SOURCES test_gravity.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (gravitycov_tests
TEST_SOURCES test_GravityCov.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

add_pfunit_ctest (tides_tests
TEST_SOURCES test_tides.pf
LINK_LIBRARIES neptune ${LIBSLAM}
)

)
125 changes: 125 additions & 0 deletions tests/test_GravityCov.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
!==============================================================================
!
!> @anchor test_gravityCov
!!
!> @brief Program for testing the function that calculates the gravityCovariance
!!
!> @author Arkene Chouchene (AC)
!!
!> @date <ul>
!! <li>15.06.2023 (initial design)</li>
!! </ul>
!!
!! @details Program for testing gravity functions in this case getGravityCovariance
!! Sources and Examples are mentioned above every test
!------------------------------------------------------------------------
module test_GravityCov

use funit
use gravity
use slam_reduction_class, only: Reduction_type
use slam_math
use slam_error_handling

implicit none

contains

@test
subroutine test_getGravityCovariance()
! Tests Gravity covariance
! Reference Values : OREKIT

type(Reduction_type) :: reduction_handler
type(Gravity_class) :: gravity_model

real(dp), dimension(3) :: r_itrf
real(dp), dimension(3) :: v_itrf
real(dp), dimension(3,3):: cov, expected_cov
real(dp) :: time_mjd, tolerance
real(dp), dimension(3) :: accel
logical :: initialized = .false.
!** init reduction model and EOP
call initErrorHandler(control = "YES", errAction = "RETURN", traceback = "YES")
if (.not. initialized) then
reduction_handler = Reduction_type()
call reduction_handler%initEop('../../work/data')
initialized = .true.
end if

gravity_model = Gravity_class()
call gravity_model%setGeoDegree(6)
call gravity_model%setGeoCovDegree(6)

! Set Up inputs
! Test 1

call gravity_model%initGravityPotential('../../work/data')

r_itrf = (/-3485.799126707284d0, -5898.652976745232d0, 835.9701786284777d0/)
v_itrf = (/-1.3525457950562447d0, -0.2804534841971075d0, -7.4721873681232385d0/)
time_mjd = 58324.d0
! Call the subroutine to be tested
call gravity_model%getGravityAcceleration(reduction_handler, r_itrf, v_itrf, time_mjd, accel)

cov = gravity_model%getGravityCovariance(r_itrf, v_itrf)

! Set up expected outputs
expected_cov = reshape((/0.39374967173447407d-9, 0.31947373468752591d-8, -0.14864895574315657d-8, &
0.31947373468752595d-8, 0.39051986351008705d-8, -0.25245746509934525d-8, &
-0.14864895574315659d-8, -0.25245746509934525d-8, -0.42989483068353419d-8/), (/3, 3/))

! Set up tolerances
tolerance = 1e-10_dp

! Check if outputs match expected values
@assertRelativelyEqual(expected_cov, cov, tolerance)

! Test 2
call gravity_model%initGravityPotential('../../work/data')

r_itrf = (/-3485.799126707284, -5898.652976745232, 835.9701786284777/)
v_itrf = (/-1.3525457950562447, -0.2804534841971075, -7.4721873681232385/)
time_mjd = 58600.d0
! Call the subroutine to be tested
call gravity_model%getGravityAcceleration(reduction_handler, r_itrf, v_itrf, time_mjd, accel)

cov = gravity_model%getGravityCovariance(r_itrf, v_itrf)

! Set up expected outputs
expected_cov = reshape((/0.39374974311657738d-9, 0.31947377200775617d-8, -0.14864897215596233d-8, &
0.31947377200775617d-8, 0.39051990534417329d-8, -0.25245749095440029d-8, &
-0.14864897215596233d-8, -0.25245749095440029d-8, -0.42989487965583128d-8/), (/3, 3/))

! Set up tolerances
tolerance = 1e-10_dp

! Check if outputs match expected values
@assertRelativelyEqual(expected_cov, cov, tolerance)


! Test 3 :
call gravity_model%initGravityPotential('../../work/data')

r_itrf = (/31986.08889084533, 3886.249797563777, -17606.478382491812/)
v_itrf = (/-0.1326762314352175, 2.0844489979862724, -0.13643320490635982/)
time_mjd = 58324.d0
! Call the subroutine to be tested
call gravity_model%getGravityAcceleration(reduction_handler, r_itrf, v_itrf, time_mjd, accel)

cov = gravity_model%getGravityCovariance(r_itrf, v_itrf)

! Set up expected outputs
expected_cov = reshape((/-0.84889040107535929d-12, -0.10613410850253561d-12, -0.11518613812098011d-11, &
-0.10613410850253560d-12, 0.40163065395133233d-13, -0.14287823362922449d-12, &
-0.11518613812098011d-11, -0.14287823362922446d-12, 0.80872733568022548d-12/), (/3, 3/))

! Set up tolerances
tolerance = 1e-10_dp

! Check if outputs match expected values
@assertRelativelyEqual(expected_cov, cov, tolerance)

end subroutine test_getGravityCovariance

end module test_GravityCov
45 changes: 45 additions & 0 deletions tests/test_atmosphere_Exponential.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
!==============================================================================
!
!> @anchor test_atmosphere_Exponential
!!
!> @brief Program for testing the function responsable for calculating Density by Exponential model
!!
!> @author Arkene Chouchene (AC)
!!
!> @date <ul>
!! <li>15.06.2023 (initial design)</li>
!! </ul>
!!
!! @details Program for testing atmosphere functions in this case getDensityExponential
!! Sources and Examples are mentioned above every test
!------------------------------------------------------------------------
module test_atmosphere_Exponential
use funit
use atmosphere, only: Atmosphere_class, EXPONENTIAL

implicit none

contains

@test
subroutine test_getDensityExponential()
! Tests that a density is computed by the Exponential model
! Reference Values : Orekit

type(Atmosphere_class) :: atmosphere_model

atmosphere_model = Atmosphere_class()

atmosphere_model%nmodel = EXPONENTIAL
call atmosphere_model%setAtmosphereInitFlag()
call atmosphere_model%initAtmosphere('../../work/data')

! test #1
@assertRelativelyEqual(38990000.0d0, atmosphere_model%getDensityExponential(25.d0), tolerance=0.01)
! test #2
@assertRelativelyEqual(0.11635971694422577d-2, atmosphere_model%getDensityExponential(0.4688d3), tolerance=0.01)
! test #3
@assertRelativelyEqual(499706396.76297361d0, atmosphere_model%getDensityExponential(0.65d1), tolerance=0.01)
end subroutine test_getDensityExponential

end module test_atmosphere_Exponential
46 changes: 46 additions & 0 deletions tests/test_atmosphere_JB2008.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
!==============================================================================
!
!> @anchor test_atmosphere_JB2008
!!
!> @brief Program for testing the function responsable for calculating Density by JB08 model
!!
!> @author Arkene Chouchene (AC)
!!
!> @date <ul>
!! <li>15.06.2023 (initial design)</li>
!! </ul>
!!
!! @details Program for testing atmosphere functions in this case getDensityJB2008
!! Sources and Examples are mentioned above every test
!------------------------------------------------------------------------
module test_atmosphere_JB2008
use funit
use atmosphere, only: Atmosphere_class, JB08

implicit none

contains

@test
subroutine test_getDensityJB2008()
! Tests that a density is computed by the JB2008 model
! inputs taken from the JB2008_test_in file and reference values from OREKIT

type(Atmosphere_class) :: atmosphere_model

atmosphere_model = Atmosphere_class()

atmosphere_model%nmodel = JB08

call atmosphere_model%setAtmosphereInitFlag()
atmosphere_model%sgaDataFile = "SOLFSMY.TXT"
call atmosphere_model%initAtmosphere('../../work/data')

! test #1
@assertRelativelyEqual(0.12405204124422383d-002, atmosphere_model%getDensityJB2008(500.d0, 0.d0, 0.d0, 51544.d0), tolerance=0.01)
! ! test #2
@assertRelativelyEqual(0.79968484021225802d+27, atmosphere_model%getDensityJB2008(150.d0, 0.d0, 0.446d2, 58600.d0), tolerance=0.01)

end subroutine test_getDensityJB2008

end module test_atmosphere_JB2008
4 changes: 2 additions & 2 deletions tests/test_atmosphere_msis2.pf
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module test_atmosphere_msis2
call atmosphere_model%initAtmosphere('../../work/data')

! test #1
@assertRelativelyEqual(atmosphere_model%getDensityNRLMSISv2(500.d0, 0.65d1, 96.d0, 0.5276739668d5), 0.10168617826293667d-002, tolerance=0.01)
@assertRelativelyEqual(0.10168617826293667d-002, atmosphere_model%getDensityNRLMSISv2(500.d0, 0.65d1, 96.d0, 0.5276739668d5), tolerance=0.01)
! test #2
@assertRelativelyEqual(atmosphere_model%getDensityNRLMSISv2(0.4688d3, -0.195d2, 0.446d2, 0.4389981823d5), 0.20788356929965501d-002, tolerance=0.01)
@assertRelativelyEqual(0.20788356929965501d-002, atmosphere_model%getDensityNRLMSISv2(0.4688d3, -0.195d2, 0.446d2, 0.4389981823d5), tolerance=0.01)

end subroutine test_getDensityNRLMSISv2

Expand Down
5 changes: 2 additions & 3 deletions tests/test_atmosphere_nrlmsis00.pf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ module test_atmosphere_nrlmsis00
! Longitude: 0.0 ! rad

type(Atmosphere_class) :: atmosphere_model

atmosphere_model = Atmosphere_class()

atmosphere_model%nmodel = MSIS2000
call atmosphere_model%setAtmosphereInitFlag()
call atmosphere_model%initAtmosphere('../../work/data')

! @assertRelativelyEqual(atmosphere_model%getDensityMSIS2000(500.d0, 0.d0, 0.d0, 51544.d0), 0.5712d-003, tolerance=0.01)
@assertRelativelyEqual(atmosphere_model%getDensityMSIS2000(500.d0, 0.d0, 0.d0, 51544.d0), 0.79964653605310576d-003, tolerance=0.01)
@assertRelativelyEqual(0.79964653605310576d-003, atmosphere_model%getDensityMSIS2000(500.d0, 0.d0, 0.d0, 51544.d0), tolerance=0.01)

end subroutine test_getDensityMSIS2000

Expand Down
Loading

0 comments on commit 8104164

Please sign in to comment.