https://www.cdslab.org/paramonte/fortran/2
Current view: top level - test - test_pm_mathFactorial@routines.inc.F90 (source / functions) Hit Total Coverage
Test: ParaMonte 2.0.0 :: Serial Fortran - Code Coverage Report Lines: 62 62 100.0 %
Date: 2024-04-08 03:18:57 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!                                                                                                                            !!!!
       4             : !!!!    ParaMonte: Parallel Monte Carlo and Machine Learning Library.                                                           !!!!
       5             : !!!!                                                                                                                            !!!!
       6             : !!!!    Copyright (C) 2012-present, The Computational Data Science Lab                                                          !!!!
       7             : !!!!                                                                                                                            !!!!
       8             : !!!!    This file is part of the ParaMonte library.                                                                             !!!!
       9             : !!!!                                                                                                                            !!!!
      10             : !!!!    LICENSE                                                                                                                 !!!!
      11             : !!!!                                                                                                                            !!!!
      12             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md                                                          !!!!
      13             : !!!!                                                                                                                            !!!!
      14             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      15             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      16             : 
      17             : !>  \brief
      18             : !>  This module contains implementations of the tests of the module [pm_mathFactorial](@ref pm_mathFactorial).
      19             : !>
      20             : !>  \fintest
      21             : !>
      22             : !>  \author
      23             : !>  \AmirShahmoradi, Tuesday 2:06 AM, September 21, 2021, Dallas, TX
      24             : 
      25             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      26             : 
      27             :         use pm_kind, only: LK
      28             :         use pm_val2str, only: getStr
      29             : 
      30             : #if     getFactorial_ENABLED
      31             : 
      32             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      33             : 
      34             :         integer(IKC), allocatable   :: PosInt(:), Factorial(:), Factorial_ref(:), diff(:)
      35             : 
      36           5 :         assertion = .true._LK
      37             : 
      38           5 :         PosInt = [integer(IKC)::]
      39           5 :         Factorial_ref = [integer(IKC)::]
      40          10 :         Factorial = getFactorial(PosInt)
      41             : 
      42           5 :         call report()
      43           5 :         call test%assert(assertion, SK_"getFactorial() must yield an empty `Factorial` with an empty input `n`.")
      44             : 
      45             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      46             : 
      47          15 :         PosInt = [0_IKC]
      48          15 :         Factorial_ref = [1_IKC]
      49          15 :         Factorial = [getFactorial(PosInt(1))]
      50             : 
      51           5 :         call report()
      52           5 :         call test%assert(assertion, SK_"getFactorial() must yield 1 for `n = 0`.")
      53             : 
      54             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      55             : 
      56          15 :         PosInt = [1_IKC]
      57          15 :         Factorial_ref = [1_IKC]
      58          15 :         Factorial = [getFactorial(PosInt(1))]
      59             : 
      60           5 :         call report()
      61           5 :         call test%assert(assertion, SK_"getFactorial() must yield 1 for `n = 1`.")
      62             : 
      63             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      64             : 
      65          20 :         PosInt = [1_IKC, 2_IKC]
      66          20 :         Factorial_ref = [1_IKC, 2_IKC]
      67          30 :         Factorial = getFactorial(PosInt)
      68             : 
      69           5 :         call report()
      70           5 :         call test%assert(assertion, SK_"getFactorial() must yield `[1_IKC, 2_IKC]` for `n = [1_IKC, 2_IKC]`.")
      71             : 
      72             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      73             : 
      74          15 :         PosInt = [5_IKC]
      75          15 :         Factorial_ref = [120_IKC]
      76          20 :         Factorial = getFactorial(PosInt)
      77             : 
      78           5 :         call report()
      79           5 :         call test%assert(assertion, SK_"getFactorial() must yield `[120_IKC]` for `n = [5_IKC]`.")
      80             : 
      81             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      82             : 
      83             :     contains
      84             : 
      85             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      86             : 
      87          25 :         subroutine report()
      88          75 :             diff = abs(Factorial - Factorial_ref)
      89          50 :             assertion = assertion .and. all(diff == 0_IKC)
      90          25 :             if (test%traceable .and. .not. assertion) then
      91             :                 ! LCOV_EXCL_START
      92             :                 write(test%disp%unit,"(*(g0,:,', '))")
      93             :                 write(test%disp%unit,"(*(g0,:,', '))") "PosInt         ", PosInt
      94             :                 write(test%disp%unit,"(*(g0,:,', '))") "Factorial      ", Factorial
      95             :                 write(test%disp%unit,"(*(g0,:,', '))") "Factorial_ref  ", Factorial_ref
      96             :                 write(test%disp%unit,"(*(g0,:,', '))") "diff           ", diff
      97             :                 write(test%disp%unit,"(*(g0,:,', '))")
      98             :                 ! LCOV_EXCL_STOP
      99             :             end if
     100          25 :         end subroutine
     101             : 
     102             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     103             : 
     104             : #elif   getLogFactorial_ENABLED
     105             : 
     106             :         real(RK), parameter :: EPS = epsilon(0._RK) * 10
     107             :         real(RK), allocatable :: WholeNumber(:), Factorial(:), Factorial_ref(:), diff(:)
     108             : 
     109           4 :         assertion = .true._LK
     110             : 
     111             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     112             : 
     113           4 :         WholeNumber = [real(RK)::]
     114           4 :         Factorial_ref = log_gamma([real(RK)::])
     115           8 :         Factorial = getLogFactorial(WholeNumber)
     116             : 
     117           4 :         call report()
     118           4 :         call test%assert(assertion, SK_"getLogFactorial() must yield an empty `Factorial` with an empty input `n`.")
     119             : 
     120             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     121             : 
     122          12 :         WholeNumber = [0._RK]
     123          12 :         Factorial_ref = log_gamma(WholeNumber + 1._RK)
     124          12 :         Factorial = [getLogFactorial(WholeNumber(1))]
     125             : 
     126           4 :         call report()
     127           4 :         call test%assert(assertion, SK_"getLogFactorial() must yield correct answer for `x = 0`.")
     128             : 
     129             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     130             : 
     131          12 :         WholeNumber = [1._RK]
     132          12 :         Factorial_ref = log_gamma([1._RK])
     133          12 :         Factorial = [getLogFactorial(WholeNumber(1))]
     134             : 
     135           4 :         call report()
     136           4 :         call test%assert(assertion, SK_"getLogFactorial() must yield correct answer for `x = 1`.")
     137             : 
     138             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     139             : 
     140          16 :         WholeNumber = [1._RK, 2._RK]
     141          16 :         Factorial_ref = log_gamma(WholeNumber + 1._RK)
     142          24 :         Factorial = getLogFactorial(WholeNumber)
     143             : 
     144           4 :         call report()
     145           4 :         call test%assert(assertion, SK_"getLogFactorial() must yield correct answer for `x = [1._RK, 2._RK]`.")
     146             : 
     147             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     148             : 
     149          12 :         WholeNumber = [5._RK]
     150          12 :         Factorial_ref = log_gamma(WholeNumber + 1._RK)
     151          16 :         Factorial = getLogFactorial(WholeNumber)
     152             : 
     153           4 :         call report()
     154           4 :         call test%assert(assertion, SK_"getLogFactorial() must yield correct answer for `x = [5._RK]`.")
     155             : 
     156             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     157             : 
     158             :     contains
     159             : 
     160             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     161             : 
     162          20 :         subroutine report()
     163          60 :             diff = abs(Factorial - Factorial_ref)
     164          40 :             assertion = assertion .and. all(abs(diff) <= EPS)
     165          20 :             if (test%traceable .and. .not. assertion) then
     166             :                 ! LCOV_EXCL_START
     167             :                 write(test%disp%unit,"(*(g0,:,', '))")
     168             :                 write(test%disp%unit,"(*(g0,:,', '))") "WholeNumber    ", WholeNumber
     169             :                 write(test%disp%unit,"(*(g0,:,', '))") "Factorial      ", Factorial
     170             :                 write(test%disp%unit,"(*(g0,:,', '))") "Factorial_ref  ", Factorial_ref
     171             :                 write(test%disp%unit,"(*(g0,:,', '))") "diff           ", diff
     172             :                 write(test%disp%unit,"(*(g0,:,', '))")
     173             :                 ! LCOV_EXCL_STOP
     174             :             end if
     175          20 :         end subroutine
     176             : 
     177             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     178             : 
     179             : #else
     180             : #error  "Unrecognized interface."
     181             : #endif

ParaMonte: Parallel Monte Carlo and Machine Learning Library 
The Computational Data Science Lab
© Copyright 2012 - 2024