The ParaMonte Documentation Website
Current view: top level - kernel/tests - Test_CorrCoef_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 24 24 100.0 %
Date: 2021-01-08 13:07:16 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 [CorrCoef_mod](@ref corrcoef_mod).
      44             : !>  \author Amir Shahmoradi
      45             : 
      46             : module Test_CorrCoef_mod
      47             : 
      48             :     use CorrCoef_mod
      49             :     use Err_mod, only: Err_type
      50             :     use Test_mod, only: Test_type
      51             :     implicit none
      52             : 
      53             :     private
      54             :     public :: test_CorrCoef
      55             : 
      56             :     type(Test_type) :: Test
      57             :     integer, parameter  :: ndata = 50
      58             :     real(RK), parameter :: Data1(ndata) = &
      59             :                                         [ 120.131280000000_RK &
      60             :                                         , 118.789800000000_RK &
      61             :                                         , 118.895800000000_RK &
      62             :                                         , 119.379160000000_RK &
      63             :                                         , 117.751090000000_RK &
      64             :                                         , 115.396630000000_RK &
      65             :                                         , 113.495780000000_RK &
      66             :                                         , 114.635740000000_RK &
      67             :                                         , 117.231620000000_RK &
      68             :                                         , 118.123780000000_RK &
      69             :                                         , 119.710750000000_RK &
      70             :                                         , 117.265190000000_RK &
      71             :                                         , 114.134970000000_RK &
      72             :                                         , 121.689170000000_RK &
      73             :                                         , 115.801760000000_RK &
      74             :                                         , 117.407520000000_RK &
      75             :                                         , 118.966600000000_RK &
      76             :                                         , 121.113780000000_RK &
      77             :                                         , 115.724250000000_RK &
      78             :                                         , 118.406980000000_RK &
      79             :                                         , 117.778200000000_RK &
      80             :                                         , 115.731490000000_RK &
      81             :                                         , 119.184340000000_RK &
      82             :                                         , 117.686110000000_RK &
      83             :                                         , 119.619380000000_RK &
      84             :                                         , 115.007830000000_RK &
      85             :                                         , 118.544290000000_RK &
      86             :                                         , 119.010710000000_RK &
      87             :                                         , 117.242960000000_RK &
      88             :                                         , 116.145870000000_RK &
      89             :                                         , 117.908530000000_RK &
      90             :                                         , 118.999680000000_RK &
      91             :                                         , 113.657890000000_RK &
      92             :                                         , 114.844810000000_RK &
      93             :                                         , 117.666480000000_RK &
      94             :                                         , 114.232200000000_RK &
      95             :                                         , 114.647730000000_RK &
      96             :                                         , 120.284660000000_RK &
      97             :                                         , 115.660780000000_RK &
      98             :                                         , 117.098840000000_RK &
      99             :                                         , 114.627280000000_RK &
     100             :                                         , 117.065790000000_RK &
     101             :                                         , 116.938190000000_RK &
     102             :                                         , 121.164640000000_RK &
     103             :                                         , 116.831740000000_RK &
     104             :                                         , 118.905820000000_RK &
     105             :                                         , 117.057260000000_RK &
     106             :                                         , 116.203920000000_RK &
     107             :                                         , 116.729220000000_RK &
     108             :                                         , 118.009200000000_RK ]
     109             :     real(RK), parameter :: Data2(ndata) = &
     110             :                                         [ 5.28935260000000_RK &
     111             :                                         , 5.50145870000000_RK &
     112             :                                         , 5.89022390000000_RK &
     113             :                                         , 5.06549460000000_RK &
     114             :                                         , 5.62128260000000_RK &
     115             :                                         , 4.49246930000000_RK &
     116             :                                         , 3.54559920000000_RK &
     117             :                                         , 4.17171310000000_RK &
     118             :                                         , 5.34432780000000_RK &
     119             :                                         , 4.30855910000000_RK &
     120             :                                         , 6.12466330000000_RK &
     121             :                                         , 4.45103540000000_RK &
     122             :                                         , 4.08259680000000_RK &
     123             :                                         , 7.64761290000000_RK &
     124             :                                         , 6.53095480000000_RK &
     125             :                                         , 6.07550490000000_RK &
     126             :                                         , 7.32100850000000_RK &
     127             :                                         , 5.82501650000000_RK &
     128             :                                         , 4.19347540000000_RK &
     129             :                                         , 4.89687790000000_RK &
     130             :                                         , 5.61290890000000_RK &
     131             :                                         , 5.70994940000000_RK &
     132             :                                         , 5.00047920000000_RK &
     133             :                                         , 5.47741520000000_RK &
     134             :                                         , 4.99151560000000_RK &
     135             :                                         , 5.08172850000000_RK &
     136             :                                         , 5.98773500000000_RK &
     137             :                                         , 6.97849360000000_RK &
     138             :                                         , 6.91612860000000_RK &
     139             :                                         , 4.90595890000000_RK &
     140             :                                         , 5.71852950000000_RK &
     141             :                                         , 4.12146660000000_RK &
     142             :                                         , 5.51241440000000_RK &
     143             :                                         , 5.26293780000000_RK &
     144             :                                         , 5.14932990000000_RK &
     145             :                                         , 4.14738170000000_RK &
     146             :                                         , 5.55786790000000_RK &
     147             :                                         , 7.08800450000000_RK &
     148             :                                         , 6.08987380000000_RK &
     149             :                                         , 4.73697940000000_RK &
     150             :                                         , 3.80934450000000_RK &
     151             :                                         , 6.03942270000000_RK &
     152             :                                         , 5.96600840000000_RK &
     153             :                                         , 6.06674510000000_RK &
     154             :                                         , 5.84361600000000_RK &
     155             :                                         , 6.19013970000000_RK &
     156             :                                         , 4.43891700000000_RK &
     157             :                                         , 4.45833300000000_RK &
     158             :                                         , 5.47659170000000_RK &
     159             :                                         , 4.65761920000000_RK ]
     160             : 
     161             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     162             : 
     163             : contains
     164             : 
     165             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     166             : 
     167           3 :     subroutine test_CorrCoef()
     168             :         implicit none
     169           3 :         Test = Test_type(moduleName=MODULE_NAME)
     170           3 :         call Test%run(test_getCorrCoefSpearman_1, "test_getCorrCoefSpearman_1")
     171           3 :         call Test%run(test_getCorrCoefSpearman_2, "test_getCorrCoefSpearman_2")
     172           3 :         call Test%finalize()
     173           3 :     end subroutine test_CorrCoef
     174             : 
     175             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     176             : 
     177           3 :     function test_getCorrCoefSpearman_1() result(assertion)
     178             : 
     179           3 :         use System_mod, only: sleep
     180             :         use Constants_mod, only: RK, IK
     181             :         use CorrCoef_mod
     182             : 
     183             :         implicit none
     184             : 
     185             :         logical :: assertion
     186           3 :         type(CorrCoefSpearman_type) :: Spearman
     187             :         real(RK)                    :: CorrCoef_ref = 0.443361344537815_RK, CorrPval_ref = 0.00140031209338936_RK
     188             : 
     189             :         call Spearman%get   ( ndata             = ndata                     &
     190             :                             , Data1             = Data1                     &
     191             :                             , Data2             = Data2                     &
     192             :                             , rho               = Spearman%rho              &
     193             :                             , rhoProb           = Spearman%rhoProb          &
     194             :                             , dStarStar         = Spearman%dStarStar        &
     195             :                             , dStarStarSignif   = Spearman%dStarStarSignif  &
     196             :                             , dStarStarProb     = Spearman%dStarStarProb    &
     197             :                             , Err               = Spearman%Err              &
     198           3 :                             )
     199           3 :         if (Spearman%Err%occurred) then
     200             :         ! LCOV_EXCL_START
     201             :             assertion = .false.
     202             :             if (Test%isDebugMode .and. .not. assertion) then
     203             :                 write(Test%outputUnit,"(*(g0))") "Error occurred: "//Spearman%Err%msg
     204             :             end if
     205             :             return
     206             :         end if
     207             :         ! LCOV_EXCL_STOP
     208             : 
     209           3 :         assertion = abs(Spearman%rho - CorrCoef_ref) / (Spearman%rho + CorrCoef_ref) < 1.e-10_RK
     210           3 :         assertion = assertion .and. abs(Spearman%rhoProb-CorrPval_ref) / (Spearman%rhoProb+CorrPval_ref) < 1.e-1_RK
     211             : 
     212           3 :         if (Test%isDebugMode .and. .not. assertion) then
     213             :         ! LCOV_EXCL_START
     214             :             write(Test%outputUnit,"(*(g0))")
     215             :             write(Test%outputUnit,"(*(g0))") "Computed Spearman's statistic:"
     216             :             write(Test%outputUnit,"(*(g0))") "rho               = ", Spearman%rho
     217             :             write(Test%outputUnit,"(*(g0))") "rhoProb           = ", Spearman%rhoProb
     218             :             write(Test%outputUnit,"(*(g0))") "dStarStar         = ", Spearman%dStarStar
     219             :             write(Test%outputUnit,"(*(g0))") "dStarStarSignif   = ", Spearman%dStarStarSignif
     220             :             write(Test%outputUnit,"(*(g0))") "dStarStarProb     = ", Spearman%dStarStarProb
     221             :             write(Test%outputUnit,"(*(g0))")
     222             :             write(Test%outputUnit,"(*(g0))") "Reference Spearman's statistic:"
     223             :             write(Test%outputUnit,"(*(g0))") "rho               = ", CorrCoef_ref
     224             :             write(Test%outputUnit,"(*(g0))") "rhoProb           = ", CorrPval_ref
     225             :             write(Test%outputUnit,"(*(g0))")
     226             :         end if
     227             :         ! LCOV_EXCL_STOP
     228             : 
     229           3 :     end function test_getCorrCoefSpearman_1
     230             : 
     231             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     232             : 
     233           3 :     function test_getCorrCoefSpearman_2() result(assertion)
     234             : 
     235           3 :         use System_mod, only: sleep
     236             :         use Constants_mod, only: RK, IK
     237             :         use CorrCoef_mod
     238             : 
     239             :         implicit none
     240             : 
     241             :         logical :: assertion
     242           3 :         type(CorrCoefSpearman_type) :: Spearman
     243             :         real(RK)                    :: CorrCoef_ref = 0.443361344537815_RK, CorrPval_ref = 0.00140031209338936_RK
     244             : 
     245             :         call getCorrCoefSpearman( ndata             = ndata                     &
     246             :                                 , Data1             = Data1                     &
     247             :                                 , Data2             = Data2                     &
     248             :                                 , rho               = Spearman%rho              &
     249             :                                 , rhoProb           = Spearman%rhoProb          &
     250             :                                 , dStarStar         = Spearman%dStarStar        &
     251             :                                 , dStarStarSignif   = Spearman%dStarStarSignif  &
     252             :                                 , dStarStarProb     = Spearman%dStarStarProb    &
     253             :                                 , Err               = Spearman%Err              &
     254           3 :                                 )
     255           3 :         if (Spearman%Err%occurred) then
     256             :         ! LCOV_EXCL_START
     257             :             assertion = .false.
     258             :             if (Test%isDebugMode .and. .not. assertion) then
     259             :                 write(Test%outputUnit,"(*(g0))") "Error occurred: "//Spearman%Err%msg
     260             :             end if
     261             :             return
     262             :         end if
     263             :         ! LCOV_EXCL_STOP
     264             : 
     265           3 :         assertion = abs(Spearman%rho - CorrCoef_ref) / (Spearman%rho + CorrCoef_ref) < 1.e-10_RK
     266           3 :         assertion = assertion .and. abs(Spearman%rhoProb-CorrPval_ref) / (Spearman%rhoProb+CorrPval_ref) < 1.e-1_RK
     267             : 
     268           3 :         if (Test%isDebugMode .and. .not. assertion) then
     269             :         ! LCOV_EXCL_START
     270             :             write(Test%outputUnit,"(*(g0))")
     271             :             write(Test%outputUnit,"(*(g0))") "Computed Spearman's statistic:"
     272             :             write(Test%outputUnit,"(*(g0))") "rho               = ", Spearman%rho
     273             :             write(Test%outputUnit,"(*(g0))") "rhoProb           = ", Spearman%rhoProb
     274             :             write(Test%outputUnit,"(*(g0))") "dStarStar         = ", Spearman%dStarStar
     275             :             write(Test%outputUnit,"(*(g0))") "dStarStarSignif   = ", Spearman%dStarStarSignif
     276             :             write(Test%outputUnit,"(*(g0))") "dStarStarProb     = ", Spearman%dStarStarProb
     277             :             write(Test%outputUnit,"(*(g0))")
     278             :             write(Test%outputUnit,"(*(g0))") "Reference Spearman's statistic:"
     279             :             write(Test%outputUnit,"(*(g0))") "rho               = ", CorrCoef_ref
     280             :             write(Test%outputUnit,"(*(g0))") "rhoProb           = ", CorrPval_ref
     281             :             write(Test%outputUnit,"(*(g0))")
     282             :         end if
     283             :         ! LCOV_EXCL_STOP
     284             : 
     285           3 :     end function test_getCorrCoefSpearman_2
     286             : 
     287             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     288             : 
     289             : end module Test_CorrCoef_mod

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021