Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!!
4 : !!!! MIT License
5 : !!!!
6 : !!!! ParaMonte: plain powerful parallel Monte Carlo library.
7 : !!!!
8 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab
9 : !!!!
10 : !!!! This file is part of the ParaMonte library.
11 : !!!!
12 : !!!! Permission is hereby granted, free of charge, to any person obtaining a
13 : !!!! copy of this software and associated documentation files (the "Software"),
14 : !!!! to deal in the Software without restriction, including without limitation
15 : !!!! the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : !!!! and/or sell copies of the Software, and to permit persons to whom the
17 : !!!! Software is furnished to do so, subject to the following conditions:
18 : !!!!
19 : !!!! The above copyright notice and this permission notice shall be
20 : !!!! included in all copies or substantial portions of the Software.
21 : !!!!
22 : !!!! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 : !!!! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 : !!!! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 : !!!! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26 : !!!! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27 : !!!! OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28 : !!!! OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 : !!!!
30 : !!!! ACKNOWLEDGMENT
31 : !!!!
32 : !!!! ParaMonte is an honor-ware and its currency is acknowledgment and citations.
33 : !!!! As per the ParaMonte library license agreement terms, if you use any parts of
34 : !!!! this library for any purposes, kindly acknowledge the use of ParaMonte in your
35 : !!!! work (education/research/industry/development/...) by citing the ParaMonte
36 : !!!! library as described on this page:
37 : !!!!
38 : !!!! https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
39 : !!!!
40 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 :
43 : !> \brief This module contains tests of the module [Math_mod](@ref math_mod).
44 : !> \author Amir Shahmoradi
45 :
46 : module Test_Math_mod
47 :
48 : use Math_mod
49 : use Err_mod, only: Err_type
50 : use Test_mod, only: Test_type
51 : implicit none
52 :
53 : private
54 : public :: test_Math
55 :
56 : type(Test_type) :: Test
57 :
58 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 :
60 : contains
61 :
62 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 :
64 3 : subroutine test_Math()
65 : implicit none
66 3 : Test = Test_type(moduleName=MODULE_NAME)
67 3 : call Test%run(test_getCumSum_IK_1, "test_getCumSum_IK_1")
68 3 : call Test%run(test_getCumSum_RK_1, "test_getCumSum_RK_1")
69 3 : call Test%run(test_getFactorial_1, "test_getFactorial_1")
70 3 : call Test%run(test_getDistanceSq_1, "test_getDistanceSq_1")
71 3 : call Test%run(test_getEllVolCoef_1, "test_getEllVolCoef_1")
72 3 : call Test%run(test_getEllVolCoef_2, "test_getEllVolCoef_2")
73 3 : call Test%run(test_getLowerGamma_1, "test_getLowerGamma_1")
74 3 : call Test%run(test_getLowerGamma_2, "test_getLowerGamma_2")
75 3 : call Test%run(test_getLowerGamma_3, "test_getLowerGamma_3")
76 3 : call Test%run(test_getLowerGamma_4, "test_getLowerGamma_4")
77 3 : call Test%run(test_getLowerGamma_5, "test_getLowerGamma_5")
78 3 : call Test%run(test_getUpperGamma_1, "test_getUpperGamma_1")
79 3 : call Test%run(test_getUpperGamma_2, "test_getUpperGamma_2")
80 3 : call Test%run(test_getUpperGamma_3, "test_getUpperGamma_3")
81 3 : call Test%run(test_getUpperGamma_4, "test_getUpperGamma_4")
82 3 : call Test%run(test_getUpperGamma_5, "test_getUpperGamma_5")
83 3 : call Test%run(test_getGammaSeries_1, "test_getGammaSeries_1")
84 3 : call Test%run(test_getLogSubExp_RK_1, "test_getLogSubExp_RK_1")
85 3 : call Test%run(test_getLogSumExp_RK_1, "test_getLogSumExp_RK_1")
86 3 : call Test%run(test_getLogSumExp_RK_2, "test_getLogSumExp_RK_2")
87 3 : call Test%run(test_getLogSumExp_CK_1, "test_getLogSumExp_CK_1")
88 3 : call Test%run(test_getLogSumExp_CK_2, "test_getLogSumExp_CK_2")
89 3 : call Test%run(test_getLogFactorial_1, "test_getLogFactorial_1")
90 3 : call Test%run(test_getGammaHalfInt_1, "test_getGammaHalfInt_1")
91 3 : call Test%run(test_getGammaContFrac_1, "test_getGammaContFrac_1")
92 3 : call Test%run(test_getLogEllVolCoef_1, "test_getLogEllVolCoef_1")
93 3 : call Test%run(test_getLogEllVolCoef_2, "test_getLogEllVolCoef_2")
94 3 : call Test%run(test_getLogEggBoxSD_RK_1, "test_getLogEggBoxSD_RK_1")
95 3 : call Test%run(test_getLogEggBoxSD_CK_1, "test_getLogEggBoxSD_CK_1")
96 3 : call Test%run(test_getLogEggBoxMD_RK_1, "test_getLogEggBoxMD_RK_1")
97 3 : call Test%run(test_getLogEggBoxMD_CK_1, "test_getLogEggBoxMD_CK_1")
98 3 : call Test%run(test_getLogVolUnitBall_1, "test_getLogVolUnitBall_1")
99 3 : call Test%run(test_getLogVolUnitBall_2, "test_getLogVolUnitBall_2")
100 3 : call Test%run(test_getLogGammaHalfInt_1, "test_getLogGammaHalfInt_1")
101 3 : call Test%run(test_getLogVolEllipsoid_1, "test_getLogVolEllipsoid_1")
102 3 : call Test%run(test_getLogVolEllipsoids_1, "test_getLogVolEllipsoids_1")
103 3 : call Test%run(test_getCumSumReverse_IK_1, "test_getCumSumReverse_IK_1")
104 3 : call Test%run(test_getCumSumReverse_RK_1, "test_getCumSumReverse_RK_1")
105 3 : call Test%run(test_getCorCeofFromFisherTrans_1, "test_getCorCeofFromFisherTrans_1")
106 3 : call Test%run(test_getFisherTransFromcorCoef_1, "test_getFisherTransFromcorCoef_1")
107 3 : call Test%finalize()
108 3 : end subroutine test_Math
109 :
110 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 :
112 3 : function test_getDistanceSq_1() result(assertion)
113 3 : use Constants_mod, only: RK, IK
114 : implicit none
115 : logical :: assertion
116 : real(RK), parameter :: Point1(*) = [0._RK, 1._RK, 2._RK, 3._RK, 4._RK]
117 : real(RK), parameter :: Point2(*) = Point1 + 1._RK
118 : real(RK), parameter :: tolerance = 1.e-10_RK
119 : real(RK), parameter :: distanceSq_ref = norm2(Point2-Point1)**2
120 3 : real(RK) :: distanceSq
121 3 : real(RK) :: difference
122 3 : distanceSq = getDistanceSq(nd = size(Point1), Point1 = Point1, Point2 = Point2)
123 3 : difference = abs(distanceSq - distanceSq_ref) / distanceSq_ref
124 3 : assertion = difference < tolerance
125 3 : if (Test%isDebugMode .and. .not. assertion) then
126 : ! LCOV_EXCL_START
127 : write(Test%outputUnit,"(*(g0,:,' '))")
128 : write(Test%outputUnit,"(*(g0,:,' '))") "distanceSq_ref = ", distanceSq_ref
129 : write(Test%outputUnit,"(*(g0,:,' '))") "distanceSq = ", distanceSq
130 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
131 : write(Test%outputUnit,"(*(g0,:,' '))")
132 : end if
133 : ! LCOV_EXCL_STOP
134 3 : end function test_getDistanceSq_1
135 :
136 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 :
138 3 : function test_getCorCeofFromFisherTrans_1() result(assertion)
139 3 : use Constants_mod, only: RK, IK
140 : implicit none
141 : logical :: assertion
142 : real(RK), parameter :: fisherTrans = 1.5_RK
143 : real(RK), parameter :: corCoef_ref = 0.905148253644866_RK ! tanh(fisherTrans)
144 : real(RK), parameter :: tolerance = 1.e-10_RK
145 3 : real(RK) :: corCoef
146 3 : real(RK) :: difference
147 3 : corCoef = getCorCeofFromFisherTrans(fisherTrans = fisherTrans)
148 3 : difference = abs(corCoef - corCoef_ref) / corCoef_ref
149 3 : assertion = difference < tolerance
150 3 : if (Test%isDebugMode .and. .not. assertion) then
151 : ! LCOV_EXCL_START
152 : write(Test%outputUnit,"(*(g0,:,' '))")
153 : write(Test%outputUnit,"(*(g0,:,' '))") "corCoef_ref = ", corCoef_ref
154 : write(Test%outputUnit,"(*(g0,:,' '))") "corCoef = ", corCoef
155 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
156 : write(Test%outputUnit,"(*(g0,:,' '))")
157 : end if
158 : ! LCOV_EXCL_STOP
159 3 : end function test_getCorCeofFromFisherTrans_1
160 :
161 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 :
163 3 : function test_getFisherTransFromcorCoef_1() result(assertion)
164 3 : use Constants_mod, only: RK, IK
165 : implicit none
166 : logical :: assertion
167 : real(RK), parameter :: corCoef = 0.905148253644866_RK ! tanh(fisherTrans)
168 : real(RK), parameter :: fisherTrans_ref = 1.5_RK
169 : real(RK), parameter :: tolerance = 1.e-10_RK
170 3 : real(RK) :: fisherTrans
171 3 : real(RK) :: difference
172 3 : fisherTrans = getFisherTransFromcorCoef(corCoef = corCoef)
173 3 : difference = abs(fisherTrans - fisherTrans_ref) / fisherTrans_ref
174 3 : assertion = difference < tolerance
175 3 : if (Test%isDebugMode .and. .not. assertion) then
176 : ! LCOV_EXCL_START
177 : write(Test%outputUnit,"(*(g0,:,' '))")
178 : write(Test%outputUnit,"(*(g0,:,' '))") "fisherTrans_ref = ", fisherTrans_ref
179 : write(Test%outputUnit,"(*(g0,:,' '))") "fisherTrans = ", fisherTrans
180 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
181 : write(Test%outputUnit,"(*(g0,:,' '))")
182 : end if
183 : ! LCOV_EXCL_STOP
184 3 : end function test_getFisherTransFromcorCoef_1
185 :
186 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 :
188 3 : function test_getCumSum_IK_1() result(assertion)
189 3 : use Constants_mod, only: RK, IK
190 : implicit none
191 : logical :: assertion
192 : integer(IK) :: i
193 : integer(IK), parameter :: CumSum_ref(*) = [1_IK, 3_IK, 6_IK, 10_IK, 15_IK, 21_IK, 28_IK, 36_IK, 45_IK, 55_IK]
194 : integer(IK), parameter :: Vector(*) = [(i,i=1,size(CumSum_ref))]
195 : integer(IK), allocatable :: CumSum(:)
196 : integer(IK), allocatable :: Difference(:)
197 3 : CumSum = getCumSum(vecLen = int(size(Vector),kind=IK), Vec = Vector)
198 : ! Gfortran 7.1 fails to automatically reallocate this array. This is not implemented in Gfortran 7.0.0
199 3 : if (allocated(Difference)) deallocate(Difference); allocate(Difference, mold = CumSum)
200 36 : Difference = abs(CumSum - CumSum_ref)
201 33 : assertion = all(Difference == 0_IK)
202 3 : if (Test%isDebugMode .and. .not. assertion) then
203 : ! LCOV_EXCL_START
204 : write(Test%outputUnit,"(*(g0,:,' '))")
205 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSum_ref = ", CumSum_ref
206 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSum = ", CumSum
207 : write(Test%outputUnit,"(*(g0,:,' '))") "Difference = ", Difference
208 : write(Test%outputUnit,"(*(g0,:,' '))")
209 : end if
210 : ! LCOV_EXCL_STOP
211 3 : end function test_getCumSum_IK_1
212 :
213 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 :
215 3 : function test_getCumSum_RK_1() result(assertion)
216 3 : use Constants_mod, only: RK, IK
217 : implicit none
218 : logical :: assertion
219 : integer(IK) :: i
220 : real(RK), parameter :: CumSum_ref(*) = [1._RK, 3._RK, 6._RK, 10._RK, 15._RK, 21._RK, 28._RK, 36._RK, 45._RK, 55._RK]
221 : real(RK), parameter :: Vector(*) = [(real(i,kind=RK),i=1,size(CumSum_ref))]
222 : real(RK), parameter :: tolerance = 1.e-14_RK
223 : real(RK), allocatable :: CumSum(:)
224 : real(RK), allocatable :: Difference(:)
225 3 : CumSum = getCumSum(vecLen = int(size(Vector),kind=IK), Vec = Vector)
226 : ! Gfortran 7.1 fails to automatically reallocate this array. This is not implemented in Gfortran 7.0.0
227 3 : if (allocated(Difference)) deallocate(Difference); allocate(Difference, mold = CumSum)
228 36 : Difference = abs(CumSum - CumSum_ref)
229 33 : assertion = all(Difference < tolerance)
230 3 : if (Test%isDebugMode .and. .not. assertion) then
231 : ! LCOV_EXCL_START
232 : write(Test%outputUnit,"(*(g0,:,' '))")
233 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSum_ref = ", CumSum_ref
234 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSum = ", CumSum
235 : write(Test%outputUnit,"(*(g0,:,' '))") "Difference = ", Difference
236 : write(Test%outputUnit,"(*(g0,:,' '))")
237 : end if
238 : ! LCOV_EXCL_STOP
239 3 : end function test_getCumSum_RK_1
240 :
241 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 :
243 3 : function test_getCumSumReverse_IK_1() result(assertion)
244 3 : use Constants_mod, only: RK, IK
245 : implicit none
246 : logical :: assertion
247 : integer(IK) :: i
248 : integer(IK), parameter :: CumSumReverse_ref(*) = [10_IK, 19_IK, 27_IK, 34_IK, 40_IK, 45_IK, 49_IK, 52_IK, 54_IK, 55_IK]
249 : integer(IK), parameter :: Vector(*) = [(i,i=1,size(CumSumReverse_ref),1)]
250 : integer(IK), allocatable :: CumSumReverse(:)
251 : integer(IK), allocatable :: Difference(:)
252 3 : CumSumReverse = getCumSumReverse_IK(vecLen = int(size(Vector),kind=IK), Vec = Vector)
253 : ! Gfortran 7.1 fails to automatically reallocate this array. This is not implemented in Gfortran 7.0.0
254 3 : if (allocated(Difference)) deallocate(Difference); allocate(Difference, mold = CumSumReverse)
255 36 : Difference = abs(CumSumReverse - CumSumReverse_ref)
256 33 : assertion = all(Difference == 0_IK)
257 3 : if (Test%isDebugMode .and. .not. assertion) then
258 : ! LCOV_EXCL_START
259 : write(Test%outputUnit,"(*(g0,:,' '))")
260 : write(Test%outputUnit,"(*(g0,:,' '))") "Vector = ", Vector
261 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSumReverse_ref = ", CumSumReverse_ref
262 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSumReverse = ", CumSumReverse
263 : write(Test%outputUnit,"(*(g0,:,' '))") "Difference = ", Difference
264 : write(Test%outputUnit,"(*(g0,:,' '))")
265 : end if
266 : ! LCOV_EXCL_STOP
267 3 : end function test_getCumSumReverse_IK_1
268 :
269 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 :
271 3 : function test_getCumSumReverse_RK_1() result(assertion)
272 3 : use Constants_mod, only: RK, IK
273 : implicit none
274 : logical :: assertion
275 : integer(IK) :: i
276 : real(RK), parameter :: CumSumReverse_ref(*) = [10._RK, 19._RK, 27._RK, 34._RK, 40._RK, 45._RK, 49._RK, 52._RK, 54._RK, 55._RK]
277 : real(RK), parameter :: Vector(*) = [(real(i,kind=RK),i=1,size(CumSumReverse_ref))]
278 : real(RK), parameter :: tolerance = 1.e-14_RK
279 : real(RK), allocatable :: CumSumReverse(:)
280 : real(RK), allocatable :: Difference(:)
281 3 : CumSumReverse = getCumSumReverse_RK(vecLen = int(size(Vector),kind=IK), Vec = Vector)
282 : ! Gfortran 7.1 fails to automatically reallocate this array. This is not implemented in Gfortran 7.0.0
283 3 : if (allocated(Difference)) deallocate(Difference); allocate(Difference, mold = CumSumReverse)
284 36 : Difference = abs(CumSumReverse - CumSumReverse_ref)
285 33 : assertion = all(Difference < tolerance)
286 3 : if (Test%isDebugMode .and. .not. assertion) then
287 : ! LCOV_EXCL_START
288 : write(Test%outputUnit,"(*(g0,:,' '))")
289 : write(Test%outputUnit,"(*(g0,:,' '))") "Vector = ", Vector
290 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSumReverse_ref = ", CumSumReverse_ref
291 : write(Test%outputUnit,"(*(g0,:,' '))") "CumSumReverse = ", CumSumReverse
292 : write(Test%outputUnit,"(*(g0,:,' '))") "Difference = ", Difference
293 : write(Test%outputUnit,"(*(g0,:,' '))")
294 : end if
295 : ! LCOV_EXCL_STOP
296 3 : end function test_getCumSumReverse_RK_1
297 :
298 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 :
300 3 : function test_getLogSubExp_RK_1() result(assertion)
301 3 : use Constants_mod, only: RK, IK
302 : implicit none
303 : logical :: assertion
304 : real(RK), parameter :: logTiny2 = log(2*tiny(1._RK))
305 : real(RK), parameter :: logTiny1 = log(2._RK) + logTiny2
306 : real(RK), parameter :: tolerance = 1.e-10_RK
307 : real(RK), parameter :: logSubExp_ref = -707.7032713517043_RK
308 3 : real(RK) :: logSubExp
309 3 : real(RK) :: difference
310 3 : logSubExp = getLogSubExp_RK(logValueLarger = logTiny1, logValueSamller = logTiny2)
311 3 : difference = abs(logSubExp - logSubExp_ref)
312 3 : assertion = difference < tolerance
313 3 : if (Test%isDebugMode .and. .not. assertion) then
314 : ! LCOV_EXCL_START
315 : write(Test%outputUnit,"(*(g0,:,' '))")
316 : write(Test%outputUnit,"(*(g0,:,' '))") "logSubExp_ref = ", logSubExp_ref
317 : write(Test%outputUnit,"(*(g0,:,' '))") "logSubExp = ", logSubExp
318 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
319 : write(Test%outputUnit,"(*(g0,:,' '))")
320 : end if
321 : ! LCOV_EXCL_STOP
322 3 : end function test_getLogSubExp_RK_1
323 :
324 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 :
326 3 : function test_getLogSumExp_RK_1() result(assertion)
327 3 : use Constants_mod, only: RK, IK
328 : implicit none
329 : logical :: assertion
330 : real(RK), parameter :: LogValue(*) = [ log(0.5*huge(1._RK)), log(0.9*huge(1._RK)), log(0.1*huge(1._RK)) ]
331 : real(RK), parameter :: tolerance = 1.e-10_RK
332 : real(RK), parameter :: logSumExp_ref = 710.1881779865910_RK
333 3 : real(RK) :: logSumExp
334 3 : real(RK) :: difference
335 3 : logSumExp = getLogSumExp_RK(lenLogValue = size(LogValue), LogValue = LogValue, maxLogValue = maxval(LogValue))
336 3 : difference = abs(logSumExp - logSumExp_ref)
337 3 : assertion = difference < tolerance
338 3 : if (Test%isDebugMode .and. .not. assertion) then
339 : ! LCOV_EXCL_START
340 : write(Test%outputUnit,"(*(g0,:,' '))")
341 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp_ref = ", logSumExp_ref
342 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp = ", logSumExp
343 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
344 : write(Test%outputUnit,"(*(g0,:,' '))")
345 : end if
346 : ! LCOV_EXCL_STOP
347 3 : end function test_getLogSumExp_RK_1
348 :
349 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350 :
351 3 : function test_getLogSumExp_RK_2() result(assertion)
352 3 : use Constants_mod, only: RK, IK
353 : implicit none
354 : logical :: assertion
355 : real(RK), parameter :: LogValue(*) = [ log(0.5*huge(1._RK)), log(0.9*huge(1._RK)), log(0.1*huge(1._RK)) ]
356 : real(RK), parameter :: tolerance = 1.e-10_RK
357 : real(RK), parameter :: logSumExp_ref = 710.1881779865910_RK
358 3 : real(RK) :: logSumExp
359 3 : real(RK) :: difference
360 3 : logSumExp = getLogSumExp_RK(lenLogValue = size(LogValue), LogValue = LogValue)
361 3 : difference = abs(logSumExp - logSumExp_ref)
362 3 : assertion = difference < tolerance
363 3 : if (Test%isDebugMode .and. .not. assertion) then
364 : ! LCOV_EXCL_START
365 : write(Test%outputUnit,"(*(g0,:,' '))")
366 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp_ref = ", logSumExp_ref
367 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp = ", logSumExp
368 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
369 : write(Test%outputUnit,"(*(g0,:,' '))")
370 : end if
371 : ! LCOV_EXCL_STOP
372 3 : end function test_getLogSumExp_RK_2
373 :
374 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 :
376 3 : function test_getLogSumExp_CK_1() result(assertion)
377 3 : use Constants_mod, only: RK, IK
378 : implicit none
379 : logical :: assertion
380 : complex(RK), parameter :: LogValue(*) = [ cmplx( log(0.5*huge(1._RK)), 0._RK, kind = RK ) &
381 : , cmplx( log(0.9*huge(1._RK)), 0._RK, kind = RK ) &
382 : , cmplx( log(0.1*huge(1._RK)), 0._RK, kind = RK ) &
383 : ]
384 : real(RK), parameter :: logSumExp_ref = cmplx(710.1881779865910_RK, 0._RK, RK)
385 : complex(RK), parameter :: tolerance = cmplx(1.e-10_RK, 0._RK, RK)
386 : complex(RK) :: logSumExp
387 : complex(RK) :: difference
388 : logSumExp = getLogSumExp_CK ( lenLogValue = int(size(LogValue),kind=IK) &
389 : , LogValue = LogValue &
390 : , maxLogValue = cmplx( maxval(real(LogValue,kind=RK)), kind = RK ) &
391 15 : )
392 3 : difference = abs(logSumExp - logSumExp_ref)
393 3 : assertion = real(difference,RK) < real(tolerance,RK)
394 3 : if (Test%isDebugMode .and. .not. assertion) then
395 : ! LCOV_EXCL_START
396 : write(Test%outputUnit,"(*(g0,:,' '))")
397 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp_ref = ", logSumExp_ref
398 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp = ", logSumExp
399 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
400 : write(Test%outputUnit,"(*(g0,:,' '))")
401 : end if
402 : ! LCOV_EXCL_STOP
403 3 : end function test_getLogSumExp_CK_1
404 :
405 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 :
407 3 : function test_getLogSumExp_CK_2() result(assertion)
408 3 : use Constants_mod, only: RK, IK
409 : implicit none
410 : logical :: assertion
411 : complex(RK), parameter :: LogValue(*) = [ cmplx( log(0.5*huge(1._RK)), 0._RK, kind = RK ) &
412 : , cmplx( log(0.9*huge(1._RK)), 0._RK, kind = RK ) &
413 : , cmplx( log(0.1*huge(1._RK)), 0._RK, kind = RK ) &
414 : ]
415 : real(RK), parameter :: logSumExp_ref = cmplx(710.1881779865910_RK, 0._RK, RK)
416 : complex(RK), parameter :: tolerance = cmplx(1.e-10_RK, 0._RK, RK)
417 : complex(RK) :: logSumExp
418 : complex(RK) :: difference
419 3 : logSumExp = getLogSumExp_CK(lenLogValue = int(size(LogValue),IK), LogValue = LogValue)
420 3 : difference = abs(logSumExp - logSumExp_ref)
421 3 : assertion = real(difference,RK) < real(tolerance,RK)
422 3 : if (Test%isDebugMode .and. .not. assertion) then
423 : ! LCOV_EXCL_START
424 : write(Test%outputUnit,"(*(g0,:,' '))")
425 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp_ref = ", logSumExp_ref
426 : write(Test%outputUnit,"(*(g0,:,' '))") "logSumExp = ", logSumExp
427 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
428 : write(Test%outputUnit,"(*(g0,:,' '))")
429 : end if
430 : ! LCOV_EXCL_STOP
431 3 : end function test_getLogSumExp_CK_2
432 :
433 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 :
435 3 : function test_getLogEggBoxSD_RK_1() result(assertion)
436 3 : use Constants_mod, only: RK, IK
437 : implicit none
438 : logical :: assertion
439 : real(RK), parameter :: coef = 1._RK
440 : real(RK), parameter :: point = 1.e1_RK
441 : real(RK), parameter :: constant = 1._RK
442 : real(RK), parameter :: exponent = 1._RK
443 : real(RK), parameter :: tolerance = 1.e-10_RK
444 : real(RK), parameter :: logEggBox_ref = 0.16092847092354756_RK
445 3 : real(RK) :: logEggBox
446 3 : real(RK) :: difference
447 3 : logEggBox = getLogEggBoxSD_RK(constant = constant, exponent = exponent, coef = coef, point = point)
448 3 : difference = abs(logEggBox - logEggBox_ref)
449 3 : assertion = difference < tolerance
450 3 : if (Test%isDebugMode .and. .not. assertion) then
451 : ! LCOV_EXCL_START
452 : write(Test%outputUnit,"(*(g0,:,' '))")
453 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox_ref = ", logEggBox_ref
454 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox = ", logEggBox
455 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
456 : write(Test%outputUnit,"(*(g0,:,' '))")
457 : end if
458 : ! LCOV_EXCL_STOP
459 3 : end function test_getLogEggBoxSD_RK_1
460 :
461 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 :
463 3 : function test_getLogEggBoxSD_CK_1() result(assertion)
464 3 : use Constants_mod, only: RK, IK
465 : implicit none
466 : logical :: assertion
467 : complex(RK), parameter :: coef = cmplx(1._RK, 0._RK, RK)
468 : complex(RK), parameter :: point = cmplx(1.e1_RK, 0._RK, RK)
469 : complex(RK), parameter :: constant = cmplx(1._RK, 0._RK, RK)
470 : complex(RK), parameter :: exponent = cmplx(1._RK, 0._RK, RK)
471 : complex(RK), parameter :: tolerance = cmplx(1.e-10_RK, 0._RK, RK)
472 : complex(RK), parameter :: logEggBox_ref = cmplx(0.16092847092354756_RK, 0._RK, RK)
473 : complex(RK) :: logEggBox
474 : complex(RK) :: difference
475 3 : logEggBox = getLogEggBoxSD_CK(constant = constant, exponent = exponent, coef = coef, point = point)
476 3 : difference = abs(logEggBox - logEggBox_ref)
477 3 : assertion = real(difference,RK) < real(tolerance,RK)
478 3 : if (Test%isDebugMode .and. .not. assertion) then
479 : ! LCOV_EXCL_START
480 : write(Test%outputUnit,"(*(g0,:,' '))")
481 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox_ref = ", logEggBox_ref
482 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox = ", logEggBox
483 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
484 : write(Test%outputUnit,"(*(g0,:,' '))")
485 : end if
486 : ! LCOV_EXCL_STOP
487 3 : end function test_getLogEggBoxSD_CK_1
488 :
489 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 :
491 3 : function test_getLogEggBoxMD_RK_1() result(assertion)
492 3 : use Constants_mod, only: RK, IK
493 : implicit none
494 : logical :: assertion
495 : integer(IK) , parameter :: nd = 3_IK
496 : real(RK) , parameter :: coef(nd) = [1._RK, 2._RK, 3._RK]
497 : real(RK) , parameter :: point(nd) = [1.e1_RK, 1.e2_RK, 1.e3_RK]
498 : real(RK) , parameter :: constant = 1._RK
499 : real(RK) , parameter :: exponent = 1._RK
500 : real(RK) , parameter :: tolerance = 1.e-10_RK
501 : real(RK) , parameter :: logEggBox_ref = 1.3988445480199623_RK
502 3 : real(RK) :: logEggBox
503 3 : real(RK) :: difference
504 3 : logEggBox = getLogEggBoxMD_RK(nd = nd, constant = constant, exponent = exponent, coef = coef, point = point)
505 3 : difference = abs(logEggBox - logEggBox_ref)
506 3 : assertion = difference < tolerance
507 3 : if (Test%isDebugMode .and. .not. assertion) then
508 : ! LCOV_EXCL_START
509 : write(Test%outputUnit,"(*(g0,:,' '))")
510 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox_ref = ", logEggBox_ref
511 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox = ", logEggBox
512 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
513 : write(Test%outputUnit,"(*(g0,:,' '))")
514 : end if
515 : ! LCOV_EXCL_STOP
516 3 : end function test_getLogEggBoxMD_RK_1
517 :
518 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519 :
520 3 : function test_getLogEggBoxMD_CK_1() result(assertion)
521 3 : use Constants_mod, only: RK, IK
522 : implicit none
523 : logical :: assertion
524 : integer(IK), parameter :: nd = 3_IK
525 : complex(RK), parameter :: coef(nd) = [cmplx(1._RK, 0._RK, RK), cmplx(2._RK, 0._RK, RK), cmplx(3._RK, 0._RK, RK)]
526 : complex(RK), parameter :: point(nd) = [cmplx(1.e1_RK, 0._RK, RK), cmplx(1.e2_RK, 0._RK, RK), cmplx(1.e3_RK, 0._RK, RK)]
527 : complex(RK), parameter :: constant = cmplx(1._RK, 0._RK, RK)
528 : complex(RK), parameter :: exponent = cmplx(1._RK, 0._RK, RK)
529 : complex(RK), parameter :: tolerance = cmplx(1.e-10_RK, 0._RK, RK)
530 : complex(RK), parameter :: logEggBox_ref = cmplx(1.3988445480199623_RK, 0._RK, RK)
531 : complex(RK) :: logEggBox
532 : complex(RK) :: difference
533 3 : logEggBox = getLogEggBoxMD_CK(nd = nd, constant = constant, exponent = exponent, coef = coef, point = point)
534 3 : difference = abs(logEggBox - logEggBox_ref)
535 3 : assertion = real(difference,RK) < real(tolerance,RK)
536 3 : if (Test%isDebugMode .and. .not. assertion) then
537 : ! LCOV_EXCL_START
538 : write(Test%outputUnit,"(*(g0,:,' '))")
539 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox_ref = ", logEggBox_ref
540 : write(Test%outputUnit,"(*(g0,:,' '))") "logEggBox = ", logEggBox
541 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
542 : write(Test%outputUnit,"(*(g0,:,' '))")
543 : end if
544 : ! LCOV_EXCL_STOP
545 3 : end function test_getLogEggBoxMD_CK_1
546 :
547 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 :
549 3 : function test_getFactorial_1() result(assertion)
550 : use Constants_mod, only: RK, IK ! LCOV_EXCL_LINE
551 : implicit none
552 : logical :: assertion
553 : integer(IK), parameter :: factorial_ref = 3628800_IK
554 : integer(IK), parameter :: positiveInteger = 10_IK
555 3 : real(RK) :: difference
556 3 : real(RK) :: factorial
557 3 : factorial = getFactorial(positiveInteger = positiveInteger)
558 3 : difference = abs(factorial - factorial_ref)
559 3 : assertion = difference == 0_IK
560 3 : if (Test%isDebugMode .and. .not. assertion) then
561 : ! LCOV_EXCL_START
562 : write(Test%outputUnit,"(*(g0,:,' '))")
563 : write(Test%outputUnit,"(*(g0,:,' '))") "factorial_ref = ", factorial_ref
564 : write(Test%outputUnit,"(*(g0,:,' '))") "factorial = ", factorial
565 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
566 : write(Test%outputUnit,"(*(g0,:,' '))")
567 : end if
568 : ! LCOV_EXCL_STOP
569 3 : end function test_getFactorial_1
570 :
571 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
572 :
573 3 : function test_getLogFactorial_1() result(assertion)
574 3 : use Constants_mod, only: RK, IK
575 : implicit none
576 : logical :: assertion
577 : integer(IK) , parameter :: positiveInteger = 10_IK
578 : real(RK) , parameter :: logFactorial_ref = 15.10441257307552_RK
579 : real(RK) , parameter :: tolerance = 1.e-10_RK
580 3 : real(RK) :: logFactorial
581 3 : real(RK) :: difference
582 3 : logFactorial = getLogFactorial(positiveInteger = positiveInteger)
583 3 : difference = abs(logFactorial - logFactorial_ref)
584 3 : assertion = difference < tolerance
585 3 : if (Test%isDebugMode .and. .not. assertion) then
586 : ! LCOV_EXCL_START
587 : write(Test%outputUnit,"(*(g0,:,' '))")
588 : write(Test%outputUnit,"(*(g0,:,' '))") "logFactorial_ref = ", logFactorial_ref
589 : write(Test%outputUnit,"(*(g0,:,' '))") "logFactorial = ", logFactorial
590 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
591 : write(Test%outputUnit,"(*(g0,:,' '))")
592 : end if
593 : ! LCOV_EXCL_STOP
594 3 : end function test_getLogFactorial_1
595 :
596 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
597 :
598 3 : function test_getEllVolCoef_1() result(assertion)
599 3 : use Constants_mod, only: RK, IK, PI
600 : implicit none
601 : logical :: assertion
602 : integer(IK) , parameter :: nd = 10_IK
603 : real(RK) , parameter :: tolerance = 1.e-10_RK
604 : real(RK) , parameter :: ellVolCoef_ref = PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ! 2.550164039877345_RK
605 3 : real(RK) :: ellVolCoef
606 3 : real(RK) :: difference
607 3 : ellVolCoef = getEllVolCoef(nd = nd)
608 3 : difference = abs(ellVolCoef - ellVolCoef_ref)
609 3 : assertion = difference < tolerance
610 3 : if (Test%isDebugMode .and. .not. assertion) then
611 : ! LCOV_EXCL_START
612 : write(Test%outputUnit,"(*(g0,:,' '))")
613 : write(Test%outputUnit,"(*(g0,:,' '))") "ellVolCoef_ref = ", ellVolCoef_ref
614 : write(Test%outputUnit,"(*(g0,:,' '))") "ellVolCoef = ", ellVolCoef
615 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
616 : write(Test%outputUnit,"(*(g0,:,' '))")
617 : end if
618 : ! LCOV_EXCL_STOP
619 3 : end function test_getEllVolCoef_1
620 :
621 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 :
623 3 : function test_getEllVolCoef_2() result(assertion)
624 3 : use Constants_mod, only: RK, IK, PI
625 : implicit none
626 : logical :: assertion
627 : integer(IK) , parameter :: nd = 11_IK
628 : real(RK) , parameter :: tolerance = 1.e-10_RK
629 : real(RK) , parameter :: ellVolCoef_ref = PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ! 1.884103879389900_RK
630 3 : real(RK) :: ellVolCoef
631 3 : real(RK) :: difference
632 : !integer(IK) :: i
633 : !do i = 1, 10000000
634 3 : ellVolCoef = getEllVolCoef(nd = nd)
635 : !end do
636 3 : difference = abs(ellVolCoef - ellVolCoef_ref)
637 3 : assertion = difference < tolerance
638 3 : if (Test%isDebugMode .and. .not. assertion) then
639 : ! LCOV_EXCL_START
640 : write(Test%outputUnit,"(*(g0,:,' '))")
641 : write(Test%outputUnit,"(*(g0,:,' '))") "ellVolCoef_ref = ", ellVolCoef_ref
642 : write(Test%outputUnit,"(*(g0,:,' '))") "ellVolCoef = ", ellVolCoef
643 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
644 : write(Test%outputUnit,"(*(g0,:,' '))")
645 : end if
646 : ! LCOV_EXCL_STOP
647 3 : end function test_getEllVolCoef_2
648 :
649 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650 :
651 3 : function test_getLogEllVolCoef_1() result(assertion)
652 3 : use Constants_mod, only: RK, IK, PI
653 : implicit none
654 : logical :: assertion
655 : integer(IK) , parameter :: nd = 10_IK
656 : real(RK) , parameter :: tolerance = 1.e-10_RK
657 : real(RK) , parameter :: logEllVolCoef_ref = log( PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ) ! 0.936157686464955_RK
658 3 : real(RK) :: logEllVolCoef
659 3 : real(RK) :: difference
660 3 : logEllVolCoef = getLogEllVolCoef(nd = nd)
661 3 : difference = abs(logEllVolCoef - logEllVolCoef_ref)
662 3 : assertion = difference < tolerance
663 3 : if (Test%isDebugMode .and. .not. assertion) then
664 : ! LCOV_EXCL_START
665 : write(Test%outputUnit,"(*(g0,:,' '))")
666 : write(Test%outputUnit,"(*(g0,:,' '))") "logEllVolCoef_ref = ", logEllVolCoef_ref
667 : write(Test%outputUnit,"(*(g0,:,' '))") "logEllVolCoef = ", logEllVolCoef
668 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
669 : write(Test%outputUnit,"(*(g0,:,' '))")
670 : end if
671 : ! LCOV_EXCL_STOP
672 3 : end function test_getLogEllVolCoef_1
673 :
674 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 :
676 3 : function test_getLogEllVolCoef_2() result(assertion)
677 3 : use Constants_mod, only: RK, IK, PI
678 : implicit none
679 : logical :: assertion
680 : integer(IK) , parameter :: nd = 11_IK
681 : real(RK) , parameter :: tolerance = 1.e-10_RK
682 : real(RK) , parameter :: logEllVolCoef_ref = log( PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ) ! 0.633452312314559_RK
683 3 : real(RK) :: logEllVolCoef
684 3 : real(RK) :: difference
685 : !integer(IK) :: i
686 : !do i = 1, 10000000
687 3 : logEllVolCoef = getLogEllVolCoef(nd = nd)
688 : !end do
689 3 : difference = abs(logEllVolCoef - logEllVolCoef_ref)
690 3 : assertion = difference < tolerance
691 3 : if (Test%isDebugMode .and. .not. assertion) then
692 : ! LCOV_EXCL_START
693 : write(Test%outputUnit,"(*(g0,:,' '))")
694 : write(Test%outputUnit,"(*(g0,:,' '))") "logEllVolCoef_ref = ", logEllVolCoef_ref
695 : write(Test%outputUnit,"(*(g0,:,' '))") "logEllVolCoef = ", logEllVolCoef
696 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
697 : write(Test%outputUnit,"(*(g0,:,' '))")
698 : end if
699 : ! LCOV_EXCL_STOP
700 3 : end function test_getLogEllVolCoef_2
701 :
702 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 :
704 3 : function test_getLogVolUnitBall_1() result(assertion)
705 3 : use Constants_mod, only: RK, IK, PI
706 : implicit none
707 : logical :: assertion
708 : integer(IK) , parameter :: nd = 10_IK
709 : real(RK) , parameter :: tolerance = 1.e-10_RK
710 : real(RK) , parameter :: logVolUnitBall_ref = log( PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ) ! .9361576864649548_RK
711 3 : real(RK) :: logVolUnitBall
712 3 : real(RK) :: difference
713 3 : logVolUnitBall = getLogVolUnitBall(nd = nd)
714 3 : difference = abs(logVolUnitBall - logVolUnitBall_ref)
715 3 : assertion = difference < tolerance
716 3 : if (Test%isDebugMode .and. .not. assertion) then
717 : ! LCOV_EXCL_START
718 : write(Test%outputUnit,"(*(g0,:,' '))")
719 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolUnitBall_ref = ", logVolUnitBall_ref
720 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolUnitBall = ", logVolUnitBall
721 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
722 : write(Test%outputUnit,"(*(g0,:,' '))")
723 : end if
724 : ! LCOV_EXCL_STOP
725 3 : end function test_getLogVolUnitBall_1
726 :
727 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
728 :
729 3 : function test_getLogVolUnitBall_2() result(assertion)
730 3 : use Constants_mod, only: RK, IK, PI
731 : implicit none
732 : logical :: assertion
733 : integer(IK) , parameter :: nd = 11_IK
734 : real(RK) , parameter :: tolerance = 1.e-10_RK
735 : real(RK) , parameter :: logVolUnitBall_ref = log( PI**(0.5_RK*nd) / gamma(0.5_RK*nd+1._RK) ) ! .6334523123145592_RK
736 3 : real(RK) :: logVolUnitBall
737 3 : real(RK) :: difference
738 : !integer(IK) :: i
739 : !do i = 1, 10000000
740 3 : logVolUnitBall = getLogVolUnitBall(nd = nd)
741 : !end do
742 3 : difference = abs(logVolUnitBall - logVolUnitBall_ref)
743 3 : assertion = difference < tolerance
744 3 : if (Test%isDebugMode .and. .not. assertion) then
745 : ! LCOV_EXCL_START
746 : write(Test%outputUnit,"(*(g0,:,' '))")
747 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolUnitBall_ref = ", logVolUnitBall_ref
748 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolUnitBall = ", logVolUnitBall
749 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
750 : write(Test%outputUnit,"(*(g0,:,' '))")
751 : end if
752 : ! LCOV_EXCL_STOP
753 3 : end function test_getLogVolUnitBall_2
754 :
755 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
756 :
757 3 : function test_getLogVolEllipsoid_1() result(assertion)
758 3 : use Constants_mod, only: RK, IK
759 : implicit none
760 : logical :: assertion
761 : integer(IK) , parameter :: nd = 10_IK
762 : real(RK) , parameter :: tolerance = 1.e-10_RK
763 : real(RK) , parameter :: logSqrtDetCovMat = 2._RK
764 : real(RK) , parameter :: logVolEllipsoid_ref = 2.936157686464955_RK
765 3 : real(RK) :: logVolEllipsoid
766 3 : real(RK) :: difference
767 3 : logVolEllipsoid = getLogVolEllipsoid(nd = nd, logSqrtDetCovMat = logSqrtDetCovMat)
768 3 : difference = abs(logVolEllipsoid - logVolEllipsoid_ref)
769 3 : assertion = difference < tolerance
770 3 : if (Test%isDebugMode .and. .not. assertion) then
771 : ! LCOV_EXCL_START
772 : write(Test%outputUnit,"(*(g0,:,' '))")
773 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolEllipsoid_ref = ", logVolEllipsoid_ref
774 : write(Test%outputUnit,"(*(g0,:,' '))") "logVolEllipsoid = ", logVolEllipsoid
775 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", difference
776 : write(Test%outputUnit,"(*(g0,:,' '))")
777 : end if
778 : ! LCOV_EXCL_STOP
779 3 : end function test_getLogVolEllipsoid_1
780 :
781 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 :
783 3 : function test_getLogVolEllipsoids_1() result(assertion)
784 3 : use Constants_mod, only: RK, IK
785 : implicit none
786 : integer(IK) :: i
787 : logical :: assertion
788 : integer(IK) , parameter :: nEllipsoid = 2_IK
789 : real(RK) , parameter :: tolerance = 1.e-10_RK
790 : integer(IK) , parameter :: nd = 2_IK
791 : real(RK) , parameter :: LogSqrtDetCovMat(nEllipsoid) = [ (log(real(i,RK)), i = 1, nEllipsoid) ]
792 : real(RK) , parameter :: EllipsoidVolume_ref(*) = [ 1.144729885849400_RK, 1.837877066409345_RK ]
793 : real(RK), allocatable :: EllipsoidVolume(:)
794 : real(RK), allocatable :: Difference(:)
795 3 : EllipsoidVolume = getLogVolEllipsoids(nd = nd, nEllipsoid = nEllipsoid, LogSqrtDetCovMat = LogSqrtDetCovMat)
796 : ! Gfortran 7.1 fails to automatically reallocate this array. This is not implemented in Gfortran 7.0.0
797 3 : if (allocated(Difference)) deallocate(Difference); allocate(Difference, mold = EllipsoidVolume)
798 12 : Difference = abs(EllipsoidVolume - EllipsoidVolume_ref)
799 9 : assertion = all(Difference < tolerance)
800 3 : if (Test%isDebugMode .and. .not. assertion) then
801 : ! LCOV_EXCL_START
802 : write(Test%outputUnit,"(*(g0,:,' '))")
803 : write(Test%outputUnit,"(*(g0,:,' '))") "EllipsoidVolume_ref = ", EllipsoidVolume_ref
804 : write(Test%outputUnit,"(*(g0,:,' '))") "EllipsoidVolume = ", EllipsoidVolume
805 : write(Test%outputUnit,"(*(g0,:,' '))") "difference = ", Difference
806 : write(Test%outputUnit,"(*(g0,:,' '))")
807 : end if
808 : ! LCOV_EXCL_STOP
809 3 : end function test_getLogVolEllipsoids_1
810 :
811 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 :
813 : !> \brief
814 : !> Test [getLowerGamma](@ref math_mod::getlowergamma) with a small `tolerance` input optional argument.
815 3 : function test_getLowerGamma_1() result(assertion)
816 3 : use Constants_mod, only: RK, IK
817 : implicit none
818 : integer(IK) :: i
819 : logical :: assertion
820 : integer(IK) , parameter :: ntest = 3
821 : real(RK) , parameter :: tolerance = 1.e-10_RK ! 1.e-7_RK
822 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
823 : real(RK) , parameter :: UpperLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
824 : real(RK) , parameter :: LowerGamma_ref(ntest) = [ 0.632120558828558_RK, 0.184736755476228_RK, 0.999817189367018_RK ]
825 : real(RK) :: LowerGamma(ntest)
826 3 : real(RK) :: difference
827 12 : do i = 1, ntest
828 9 : LowerGamma(i) = getLowerGamma ( exponent = Exponent(i) &
829 9 : , logGammaExponent = log_gamma(Exponent(i)) &
830 9 : , upperLim = UpperLim(i) &
831 : , tolerance = tolerance &
832 9 : )
833 9 : difference = 2 * abs(LowerGamma(i) - LowerGamma_ref(i)) / LowerGamma_ref(i)
834 9 : assertion = difference < tolerance
835 12 : if (Test%isDebugMode .and. .not. assertion) then
836 : ! LCOV_EXCL_START
837 : write(Test%outputUnit,"(*(g0,:,', '))")
838 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference LowerGamma, Computed LowerGamma, difference:"
839 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), UpperLim(i), LowerGamma(i), LowerGamma_ref(i), difference
840 : write(Test%outputUnit,"(*(g0,:,', '))")
841 : end if
842 : ! LCOV_EXCL_STOP
843 : end do
844 3 : end function test_getLowerGamma_1
845 :
846 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
847 :
848 : !> \brief
849 : !> Test [getLowerGamma](@ref math_mod::getlowergamma) with a medium `tolerance` input optional argument.
850 3 : function test_getLowerGamma_2() result(assertion)
851 3 : use Constants_mod, only: RK, IK
852 : implicit none
853 : integer(IK) :: i
854 : logical :: assertion
855 : integer(IK) , parameter :: ntest = 3
856 : real(RK) , parameter :: tolerance = 1.e-7_RK
857 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
858 : real(RK) , parameter :: UpperLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
859 : real(RK) , parameter :: LowerGamma_ref(ntest) = [ 0.632120558828558_RK, 0.184736755476228_RK, 0.999817189367018_RK ]
860 : real(RK) :: LowerGamma(ntest)
861 3 : real(RK) :: difference
862 12 : do i = 1, ntest
863 9 : LowerGamma(i) = getLowerGamma ( exponent = Exponent(i) &
864 9 : , logGammaExponent = log_gamma(Exponent(i)) &
865 9 : , upperLim = UpperLim(i) &
866 : , tolerance = tolerance &
867 9 : )
868 9 : difference = 2 * abs(LowerGamma(i) - LowerGamma_ref(i)) / LowerGamma_ref(i)
869 9 : assertion = difference < tolerance
870 12 : if (Test%isDebugMode .and. .not. assertion) then
871 : ! LCOV_EXCL_START
872 : write(Test%outputUnit,"(*(g0,:,', '))")
873 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference LowerGamma, Computed LowerGamma, difference:"
874 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), UpperLim(i), LowerGamma(i), LowerGamma_ref(i), difference
875 : write(Test%outputUnit,"(*(g0,:,', '))")
876 : end if
877 : ! LCOV_EXCL_STOP
878 : end do
879 3 : end function test_getLowerGamma_2
880 :
881 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 :
883 : !> \brief
884 : !> Test [getLowerGamma](@ref math_mod::getlowergamma) with a large `tolerance` input optional argument.
885 3 : function test_getLowerGamma_3() result(assertion)
886 3 : use Constants_mod, only: RK, IK
887 : implicit none
888 : integer(IK) :: i
889 : logical :: assertion
890 : integer(IK) , parameter :: ntest = 3
891 : real(RK) , parameter :: tolerance = 1.e-3_RK
892 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
893 : real(RK) , parameter :: UpperLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
894 : real(RK) , parameter :: LowerGamma_ref(ntest) = [ 0.632120558828558_RK, 0.184736755476228_RK, 0.999817189367018_RK ]
895 : real(RK) :: LowerGamma(ntest)
896 3 : real(RK) :: difference
897 12 : do i = 1, ntest
898 9 : LowerGamma(i) = getLowerGamma ( exponent = Exponent(i) &
899 9 : , logGammaExponent = log_gamma(Exponent(i)) &
900 9 : , upperLim = UpperLim(i) &
901 : , tolerance = tolerance &
902 9 : )
903 9 : difference = 2 * abs(LowerGamma(i) - LowerGamma_ref(i)) / LowerGamma_ref(i)
904 9 : assertion = difference < tolerance
905 12 : if (Test%isDebugMode .and. .not. assertion) then
906 : ! LCOV_EXCL_START
907 : write(Test%outputUnit,"(*(g0,:,', '))")
908 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference LowerGamma, Computed LowerGamma, difference:"
909 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), UpperLim(i), LowerGamma(i), LowerGamma_ref(i), difference
910 : write(Test%outputUnit,"(*(g0,:,', '))")
911 : end if
912 : ! LCOV_EXCL_STOP
913 : end do
914 3 : end function test_getLowerGamma_3
915 :
916 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917 :
918 : !> \brief
919 : !> Test [getLowerGamma](@ref math_mod::getlowergamma) without the `tolerance` input optional argument,
920 : !> in which case, the procedure should default to `epsilon` for the value of tolerance.
921 3 : function test_getLowerGamma_4() result(assertion)
922 3 : use Constants_mod, only: RK, IK
923 : implicit none
924 : integer(IK) :: i
925 : logical :: assertion
926 : integer(IK) , parameter :: ntest = 3
927 : real(RK) , parameter :: tolerance = epsilon(1._RK)
928 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
929 : real(RK) , parameter :: UpperLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
930 : real(RK) , parameter :: LowerGamma_ref(ntest) = [ 0.632120558828558_RK, 0.184736755476228_RK, 0.999817189367018_RK ]
931 : real(RK) :: LowerGamma(ntest)
932 3 : real(RK) :: difference
933 12 : do i = 1, ntest
934 9 : LowerGamma(i) = getLowerGamma ( exponent = Exponent(i) &
935 9 : , logGammaExponent = log_gamma(Exponent(i)) &
936 9 : , upperLim = UpperLim(i) &
937 9 : )
938 9 : difference = 2 * abs(LowerGamma(i) - LowerGamma_ref(i)) / LowerGamma_ref(i)
939 9 : assertion = difference < 1000 * tolerance
940 12 : if (Test%isDebugMode .and. .not. assertion) then
941 : ! LCOV_EXCL_START
942 : write(Test%outputUnit,"(*(g0,:,', '))")
943 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference LowerGamma, Computed LowerGamma, difference:"
944 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), UpperLim(i), LowerGamma(i), LowerGamma_ref(i), difference
945 : write(Test%outputUnit,"(*(g0,:,', '))")
946 : end if
947 : ! LCOV_EXCL_STOP
948 : end do
949 3 : end function test_getLowerGamma_4
950 :
951 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952 :
953 : !> \brief
954 : !> Test [getLowerGamma](@ref math_mod::getlowergamma) with a wrong positive value for the input argument `upperLim`.
955 3 : function test_getLowerGamma_5() result(assertion)
956 3 : use Constants_mod, only: RK, IK, HUGE_RK
957 : implicit none
958 : logical :: assertion
959 : real(RK) , parameter :: exponent = +1.0_RK
960 : real(RK) , parameter :: upperlim = -1.0_RK
961 : real(RK) , parameter :: lowerGamma_ref = -HUGE_RK
962 3 : real(RK) :: lowerGamma
963 : lowerGamma = getLowerGamma ( exponent = exponent &
964 : , logGammaExponent = log_gamma(exponent) &
965 : , upperLim = upperLim &
966 3 : )
967 3 : assertion = lowerGamma == lowerGamma_ref
968 3 : if (Test%isDebugMode .and. .not. assertion) then
969 : ! LCOV_EXCL_START
970 : write(Test%outputUnit,"(*(g0,:,', '))")
971 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference LowerGamma, Computed LowerGamma:"
972 : write(Test%outputUnit,"(*(g0,:,', '))") exponent, upperlim, lowerGamma, lowerGamma_ref
973 : write(Test%outputUnit,"(*(g0,:,', '))")
974 : end if
975 : ! LCOV_EXCL_STOP
976 3 : end function test_getLowerGamma_5
977 :
978 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 :
980 : !> \brief
981 : !> Test [getUpperGamma](@ref math_mod::getuppergamma) with a small `tolerance` input optional argument.
982 3 : function test_getUpperGamma_1() result(assertion)
983 3 : use Constants_mod, only: RK, IK
984 : implicit none
985 : integer(IK) :: i
986 : logical :: assertion
987 : integer(IK) , parameter :: ntest = 3
988 : real(RK) , parameter :: tolerance = 1.e-10_RK ! 1.e-7_RK
989 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
990 : real(RK) , parameter :: LowerLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
991 : real(RK) , parameter :: UpperGamma_ref(ntest) = [0.367879441171442_RK, 0.815263244523772_RK, 1.828106329818355e-04_RK]
992 : real(RK) :: UpperGamma(ntest)
993 3 : real(RK) :: difference
994 12 : do i = 1, ntest
995 9 : UpperGamma(i) = getUpperGamma ( exponent = Exponent(i) &
996 9 : , logGammaExponent = log_gamma(Exponent(i)) &
997 9 : , lowerLim = LowerLim(i) &
998 : , tolerance = tolerance &
999 9 : )
1000 9 : difference = 2 * abs(UpperGamma(i) - UpperGamma_ref(i)) / UpperGamma_ref(i)
1001 9 : assertion = difference < tolerance
1002 12 : if (Test%isDebugMode .and. .not. assertion) then
1003 : ! LCOV_EXCL_START
1004 : write(Test%outputUnit,"(*(g0,:,', '))")
1005 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference UpperGamma, Computed UpperGamma, difference:"
1006 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), LowerLim(i), UpperGamma(i), UpperGamma_ref(i), difference
1007 : write(Test%outputUnit,"(*(g0,:,', '))")
1008 : end if
1009 : ! LCOV_EXCL_STOP
1010 : end do
1011 3 : end function test_getUpperGamma_1
1012 :
1013 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 :
1015 : !> \brief
1016 : !> Test [getUpperGamma](@ref math_mod::getuppergamma) with a medium `tolerance` input optional argument.
1017 3 : function test_getUpperGamma_2() result(assertion)
1018 3 : use Constants_mod, only: RK, IK
1019 : implicit none
1020 : integer(IK) :: i
1021 : logical :: assertion
1022 : integer(IK) , parameter :: ntest = 3
1023 : real(RK) , parameter :: tolerance = 1.e-7_RK
1024 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
1025 : real(RK) , parameter :: LowerLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
1026 : real(RK) , parameter :: UpperGamma_ref(ntest) = [0.367879441171442_RK, 0.815263244523772_RK, 1.828106329818355e-04_RK]
1027 : real(RK) :: UpperGamma(ntest)
1028 3 : real(RK) :: difference
1029 12 : do i = 1, ntest
1030 9 : UpperGamma(i) = getUpperGamma ( exponent = Exponent(i) &
1031 9 : , logGammaExponent = log_gamma(Exponent(i)) &
1032 9 : , lowerLim = LowerLim(i) &
1033 : , tolerance = tolerance &
1034 9 : )
1035 9 : difference = 2 * abs(UpperGamma(i) - UpperGamma_ref(i)) / UpperGamma_ref(i)
1036 9 : assertion = difference < tolerance
1037 12 : if (Test%isDebugMode .and. .not. assertion) then
1038 : ! LCOV_EXCL_START
1039 : write(Test%outputUnit,"(*(g0,:,', '))")
1040 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference UpperGamma, Computed UpperGamma, difference:"
1041 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), LowerLim(i), UpperGamma(i), UpperGamma_ref(i), difference
1042 : write(Test%outputUnit,"(*(g0,:,', '))")
1043 : end if
1044 : ! LCOV_EXCL_STOP
1045 : end do
1046 3 : end function test_getUpperGamma_2
1047 :
1048 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 :
1050 : !> \brief
1051 : !> Test [getUpperGamma](@ref math_mod::getuppergamma) with a coarse `tolerance` input optional argument.
1052 3 : function test_getUpperGamma_3() result(assertion)
1053 3 : use Constants_mod, only: RK, IK
1054 : implicit none
1055 : integer(IK) :: i
1056 : logical :: assertion
1057 : integer(IK) , parameter :: ntest = 3
1058 : real(RK) , parameter :: tolerance = 1.e-3_RK
1059 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
1060 : real(RK) , parameter :: LowerLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
1061 : real(RK) , parameter :: UpperGamma_ref(ntest) = [0.367879441171442_RK, 0.815263244523772_RK, 1.828106329818355e-04_RK]
1062 : real(RK) :: UpperGamma(ntest)
1063 3 : real(RK) :: difference
1064 12 : do i = 1, ntest
1065 9 : UpperGamma(i) = getUpperGamma ( exponent = Exponent(i) &
1066 9 : , logGammaExponent = log_gamma(Exponent(i)) &
1067 9 : , lowerLim = LowerLim(i) &
1068 : , tolerance = tolerance &
1069 9 : )
1070 9 : difference = 2 * abs(UpperGamma(i) - UpperGamma_ref(i)) / UpperGamma_ref(i)
1071 9 : assertion = difference < tolerance
1072 12 : if (Test%isDebugMode .and. .not. assertion) then
1073 : ! LCOV_EXCL_START
1074 : write(Test%outputUnit,"(*(g0,:,', '))")
1075 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference UpperGamma, Computed UpperGamma, difference:"
1076 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), LowerLim(i), UpperGamma(i), UpperGamma_ref(i), difference
1077 : write(Test%outputUnit,"(*(g0,:,', '))")
1078 : end if
1079 : ! LCOV_EXCL_STOP
1080 : end do
1081 3 : end function test_getUpperGamma_3
1082 :
1083 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1084 :
1085 : !> \brief
1086 : !> Test [getUpperGamma](@ref math_mod::getuppergamma) without the `tolerance` input optional argument, in which case
1087 : !> the procedure should default to `epsilon` for the value of tolerance.
1088 3 : function test_getUpperGamma_4() result(assertion)
1089 3 : use Constants_mod, only: RK, IK
1090 : implicit none
1091 : integer(IK) :: i
1092 : logical :: assertion
1093 : integer(IK) , parameter :: ntest = 3
1094 : real(RK) , parameter :: tolerance = epsilon(1._RK)
1095 : real(RK) , parameter :: Exponent(ntest) = [1.0_RK, 5.0_RK, 0.5_RK]
1096 : real(RK) , parameter :: LowerLim(ntest) = [1.0_RK, 3.0_RK, 7.0_RK]
1097 : real(RK) , parameter :: UpperGamma_ref(ntest) = [0.367879441171442_RK, 0.815263244523772_RK, 1.828106329818355e-04_RK]
1098 : real(RK) :: UpperGamma(ntest)
1099 3 : real(RK) :: difference
1100 12 : do i = 1, ntest
1101 9 : UpperGamma(i) = getUpperGamma ( exponent = Exponent(i) &
1102 9 : , logGammaExponent = log_gamma(Exponent(i)) &
1103 9 : , lowerLim = LowerLim(i) &
1104 9 : )
1105 9 : difference = 2 * abs(UpperGamma(i) - UpperGamma_ref(i)) / UpperGamma_ref(i)
1106 9 : assertion = difference < 1000 * tolerance
1107 12 : if (Test%isDebugMode .and. .not. assertion) then
1108 : ! LCOV_EXCL_START
1109 : write(Test%outputUnit,"(*(g0,:,', '))")
1110 : write(Test%outputUnit,"(*(g0,:,', '))") "Exponent, UpperLim, Reference UpperGamma, Computed UpperGamma, difference:"
1111 : write(Test%outputUnit,"(*(g0,:,', '))") Exponent(i), LowerLim(i), UpperGamma(i), UpperGamma_ref(i), difference
1112 : write(Test%outputUnit,"(*(g0,:,', '))")
1113 : end if
1114 : ! LCOV_EXCL_STOP
1115 : end do
1116 3 : end function test_getUpperGamma_4
1117 :
1118 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1119 :
1120 : !> \brief
1121 : !> Test [getUpperGamma](@ref math_mod::getuppergamma) with a wrong positive value for the input argument `lowerLim`.
1122 3 : function test_getUpperGamma_5() result(assertion)
1123 3 : use Constants_mod, only: RK, IK, HUGE_RK
1124 : implicit none
1125 : logical :: assertion
1126 : real(RK) , parameter :: exponent = +1.0_RK
1127 : real(RK) , parameter :: lowerLim = -1.0_RK
1128 : real(RK) , parameter :: upperGamma_ref = -HUGE_RK
1129 3 : real(RK) :: upperGamma
1130 : upperGamma = getUpperGamma ( exponent = exponent &
1131 : , logGammaExponent = log_gamma(exponent) &
1132 : , lowerLim = lowerLim &
1133 3 : )
1134 3 : assertion = upperGamma == upperGamma_ref
1135 3 : if (Test%isDebugMode .and. .not. assertion) then
1136 : ! LCOV_EXCL_START
1137 : write(Test%outputUnit,"(*(g0,:,', '))")
1138 : write(Test%outputUnit,"(*(g0,:,', '))") "exponent ", exponent
1139 : write(Test%outputUnit,"(*(g0,:,', '))") "lowerLim ", lowerLim
1140 : write(Test%outputUnit,"(*(g0,:,', '))") "upperGamma ", upperGamma
1141 : write(Test%outputUnit,"(*(g0,:,', '))") "upperGamma_ref ", upperGamma_ref
1142 : write(Test%outputUnit,"(*(g0,:,', '))")
1143 : end if
1144 : ! LCOV_EXCL_STOP
1145 3 : end function test_getUpperGamma_5
1146 :
1147 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 :
1149 : !> \brief
1150 : !> Test [getGammaSeries](@ref math_mod::getgammaseries) with a zero value for the input argument `upperLim`.
1151 3 : function test_getGammaSeries_1() result(assertion)
1152 3 : use Constants_mod, only: RK, IK
1153 : implicit none
1154 : logical :: assertion
1155 : real(RK) , parameter :: exponent = +1.0_RK
1156 : real(RK) , parameter :: upperLim = 0._RK
1157 : real(RK) , parameter :: tolerance = 1.e-3_RK
1158 : real(RK) , parameter :: gammaSeries_ref = 0._RK
1159 3 : real(RK) :: gammaSeries
1160 : gammaSeries = getGammaSeries( exponent = exponent &
1161 : , logGammaExponent = log_gamma(exponent) &
1162 : , upperLim = upperLim &
1163 : , tolerance = tolerance &
1164 3 : )
1165 3 : assertion = gammaSeries == gammaSeries_ref
1166 3 : if (Test%isDebugMode .and. .not. assertion) then
1167 : ! LCOV_EXCL_START
1168 : write(Test%outputUnit,"(*(g0,:,', '))")
1169 : write(Test%outputUnit,"(*(g0,:,', '))") "exponent ", exponent
1170 : write(Test%outputUnit,"(*(g0,:,', '))") "upperLim ", upperLim
1171 : write(Test%outputUnit,"(*(g0,:,', '))") "tolerance ", tolerance
1172 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaSeries ", gammaSeries
1173 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaSeries_ref", gammaSeries_ref
1174 : write(Test%outputUnit,"(*(g0,:,', '))")
1175 : end if
1176 : ! LCOV_EXCL_STOP
1177 3 : end function test_getGammaSeries_1
1178 :
1179 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180 :
1181 : !> \brief
1182 : !> Test [getGammaContFrac](@ref math_mod::getgammacontfrac) with a zero value for the input argument `lowerLim`.
1183 3 : function test_getGammaContFrac_1() result(assertion)
1184 3 : use Constants_mod, only: RK, IK
1185 : implicit none
1186 : logical :: assertion
1187 : real(RK) , parameter :: exponent = +1.0_RK
1188 : real(RK) , parameter :: lowerLim = 0._RK
1189 : real(RK) , parameter :: tolerance = 1.e-3_RK
1190 : real(RK) , parameter :: gammaContFrac_ref = 1._RK
1191 3 : real(RK) :: gammaContFrac
1192 : gammaContFrac = getGammaContFrac( exponent = exponent &
1193 : , logGammaExponent = log_gamma(exponent) &
1194 : , lowerLim = lowerLim &
1195 : , tolerance = tolerance &
1196 3 : )
1197 3 : assertion = gammaContFrac == gammaContFrac_ref
1198 3 : if (Test%isDebugMode .and. .not. assertion) then
1199 : ! LCOV_EXCL_START
1200 : write(Test%outputUnit,"(*(g0,:,', '))")
1201 : write(Test%outputUnit,"(*(g0,:,', '))") "exponent ", exponent
1202 : write(Test%outputUnit,"(*(g0,:,', '))") "lowerLim ", lowerLim
1203 : write(Test%outputUnit,"(*(g0,:,', '))") "tolerance ", tolerance
1204 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaContFrac ", gammaContFrac
1205 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaContFrac_ref ", gammaContFrac_ref
1206 : write(Test%outputUnit,"(*(g0,:,', '))")
1207 : end if
1208 : ! LCOV_EXCL_STOP
1209 3 : end function test_getGammaContFrac_1
1210 :
1211 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1212 :
1213 : !> \brief
1214 : !> Test the accuracy of [getLogGammaHalfInt](@ref math_mod::getloggammahalfint).
1215 3 : function test_getGammaHalfInt_1() result(assertion)
1216 3 : use Constants_mod, only: RK, IK
1217 : implicit none
1218 : logical :: assertion
1219 : real(RK) , parameter :: tolerance = 1.e-10_RK
1220 : real(RK) , parameter :: positiveHalfInteger = 0.5_RK
1221 : real(RK) , parameter :: gammaHalfInt_ref = gamma(positiveHalfInteger)
1222 3 : real(RK) :: gammaHalfInt
1223 3 : real(RK) :: difference
1224 3 : gammaHalfInt = getGammaHalfInt(positiveHalfInteger)
1225 3 : difference = abs(gammaHalfInt - gammaHalfInt_ref) / abs(gammaHalfInt_ref)
1226 3 : assertion = difference < tolerance
1227 3 : if (Test%isDebugMode .and. .not. assertion) then
1228 : ! LCOV_EXCL_START
1229 : write(Test%outputUnit,"(*(g0,:,', '))")
1230 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaHalfInt_ref ", gammaHalfInt_ref
1231 : write(Test%outputUnit,"(*(g0,:,', '))") "gammaHalfInt ", gammaHalfInt
1232 : write(Test%outputUnit,"(*(g0,:,', '))") "difference ", difference
1233 : write(Test%outputUnit,"(*(g0,:,', '))") "tolerance ", tolerance
1234 : write(Test%outputUnit,"(*(g0,:,', '))")
1235 : end if
1236 : ! LCOV_EXCL_STOP
1237 3 : end function test_getGammaHalfInt_1
1238 :
1239 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1240 :
1241 : !> \brief
1242 : !> Test the accuracy of [getLogGammaHalfInt](@ref math_mod::getloggammahalfint).
1243 3 : function test_getLogGammaHalfInt_1() result(assertion)
1244 3 : use Constants_mod, only: RK, IK
1245 : implicit none
1246 : logical :: assertion
1247 : real(RK) , parameter :: tolerance = 1.e-10_RK
1248 : real(RK) , parameter :: positiveHalfInteger = 0.5_RK
1249 : real(RK) , parameter :: logGammaHalfInt_ref = log_gamma(positiveHalfInteger)
1250 3 : real(RK) :: logGammaHalfInt
1251 3 : real(RK) :: difference
1252 3 : logGammaHalfInt = getLogGammaHalfInt(positiveHalfInteger)
1253 3 : difference = abs(logGammaHalfInt - logGammaHalfInt_ref) / abs(logGammaHalfInt_ref)
1254 3 : assertion = difference < tolerance
1255 3 : if (Test%isDebugMode .and. .not. assertion) then
1256 : ! LCOV_EXCL_START
1257 : write(Test%outputUnit,"(*(g0,:,', '))")
1258 : write(Test%outputUnit,"(*(g0,:,', '))") "logGammaHalfInt_ref", logGammaHalfInt_ref
1259 : write(Test%outputUnit,"(*(g0,:,', '))") "logGammaHalfInt ", logGammaHalfInt
1260 : write(Test%outputUnit,"(*(g0,:,', '))") "difference ", difference
1261 : write(Test%outputUnit,"(*(g0,:,', '))") "tolerance ", tolerance
1262 : write(Test%outputUnit,"(*(g0,:,', '))")
1263 : end if
1264 : ! LCOV_EXCL_STOP
1265 3 : end function test_getLogGammaHalfInt_1
1266 :
1267 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268 :
1269 : end module Test_Math_mod ! LCOV_EXCL_LINE
|