The ParaMonte Documentation Website
Current view: top level - kernel/tests - Test_Timer_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: Serial Kernel - Code Coverage Report Lines: 44 44 100.0 %
Date: 2021-01-08 13:03:42 Functions: 4 4 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 [Timer_mod](@ref timer_mod).
      44             : !>  \author Amir Shahmoradi
      45             : 
      46             : module Test_Timer_mod
      47             : 
      48             :     use Timer_mod
      49             :     use Err_mod, only: Err_type
      50             :     use Test_mod, only: Test_type
      51             :     implicit none
      52             : 
      53             :     private
      54             :     public :: test_Timer
      55             : 
      56             :     type(Test_type) :: Test
      57             : 
      58             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      59             : 
      60             : contains
      61             : 
      62             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      63             : 
      64           1 :     subroutine test_Timer()
      65             : 
      66             :         implicit none
      67             : 
      68           1 :         Test = Test_type(moduleName=MODULE_NAME)
      69           1 :         call Test%run(test_Timer_type_1, "test_Timer_type_1")
      70           1 :         call Test%run(test_getTimeSinceStart_1, "test_getTimeSinceStart_1")
      71           1 :         call Test%run(test_getTimeSinceLastCall_1, "test_getTimeSinceLastCall_1")
      72           1 :         call Test%finalize()
      73             : 
      74           1 :     end subroutine test_Timer
      75             : 
      76             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      77             : 
      78           1 :     function test_Timer_type_1() result(assertion)
      79             : 
      80           1 :         use System_mod, only: sleep
      81             :         use Constants_mod, only: IK, RK
      82             :         implicit none
      83             :         real(RK), parameter :: seconds = 0.05_RK
      84             :         logical             :: assertion
      85             :         type(Timer_type)    :: Timer
      86           1 :         type(Err_type)      :: Err
      87             : 
      88           1 :         Timer = Timer_type(Err)
      89           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
      90           1 :         call sleep(seconds=seconds,Err=Err)
      91           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
      92           1 :         call Timer%toc()
      93           1 :         assertion = assertion .and. Timer%Time%total > 0._RK
      94           1 :         assertion = assertion .and. Timer%Time%delta > 0._RK
      95           1 :         assertion = assertion .and. Timer%Time%start < Timer%Time%stop
      96           1 :         assertion = assertion .and. Timer%period > 0._RK
      97             : 
      98           1 :         assertion = assertion .and. Timer%Count%total > 0_IK
      99           1 :         assertion = assertion .and. Timer%Count%delta > 0_IK
     100           1 :         assertion = assertion .and. Timer%Count%start < Timer%Count%stop
     101           1 :         assertion = assertion .and. Timer%Count%rate > 0_IK
     102           1 :         assertion = assertion .and. Timer%Count%max > 0_IK
     103             : 
     104           1 :         assertion = assertion .and. Timer%Time%delta > 0.9_RK * seconds
     105             : 
     106             :         ! LCOV_EXCL_START
     107             :         if (Test%isDebugMode .and. .not. assertion) then
     108             :             write(Test%outputUnit,"(*(g0))")
     109             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%start: ", Timer%Count%start
     110             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%rate : ", Timer%Count%rate
     111             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%max  : ", Timer%Count%max
     112             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%stop : ", Timer%Count%stop
     113             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%total: ", Timer%Count%total
     114             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%delta: ", Timer%Count%delta
     115             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%start : ", Timer%Time%start
     116             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%stop  : ", Timer%Time%stop
     117             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%total : ", Timer%Time%total
     118             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%delta : ", Timer%Time%delta
     119             :             write(Test%outputUnit,"(*(g0))")   "Timer%period     : ", Timer%period
     120             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%unit  : ", Timer%Time%unit
     121             :             write(Test%outputUnit,"(*(g0))")
     122             :         end if
     123             :         ! LCOV_EXCL_STOP
     124             : 
     125           1 :     end function test_Timer_type_1
     126             : 
     127             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     128             : 
     129           1 :     function test_getTimeSinceStart_1() result(assertion)
     130             : 
     131           1 :         use Constants_mod, only: IK, RK
     132             :         use System_mod, only: sleep
     133             :         implicit none
     134             :         real(RK), parameter :: seconds = 0.05_RK
     135             :         logical             :: assertion
     136             :         type(Timer_type)    :: Timer
     137           1 :         type(Err_type)      :: Err
     138             : 
     139           1 :         Timer = Timer_type(Err)
     140           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
     141           1 :         call sleep(seconds=seconds,Err=Err)
     142           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
     143           1 :         assertion = assertion .and. Timer%total() > 0.9_RK * seconds
     144             : 
     145             :         ! LCOV_EXCL_START
     146             :         if (Test%isDebugMode .and. .not. assertion) then
     147             :             write(Test%outputUnit,"(*(g0))")
     148             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%start: ", Timer%Count%start
     149             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%rate : ", Timer%Count%rate
     150             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%max  : ", Timer%Count%max
     151             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%stop : ", Timer%Count%stop
     152             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%total: ", Timer%Count%total
     153             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%delta: ", Timer%Count%delta
     154             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%start : ", Timer%Time%start
     155             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%stop  : ", Timer%Time%stop
     156             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%total : ", Timer%Time%total
     157             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%delta : ", Timer%Time%delta
     158             :             write(Test%outputUnit,"(*(g0))")   "Timer%period     : ", Timer%period
     159             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%unit  : ", Timer%Time%unit
     160             :             write(Test%outputUnit,"(*(g0))")
     161             :         end if
     162             :         ! LCOV_EXCL_STOP
     163             : 
     164           1 :     end function test_getTimeSinceStart_1
     165             : 
     166             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     167             : 
     168           1 :     function test_getTimeSinceLastCall_1() result(assertion)
     169             : 
     170           1 :         use System_mod, only: sleep
     171             :         use Constants_mod, only: IK, RK
     172             :         implicit none
     173             :         logical             :: assertion
     174             :         real(RK), parameter :: seconds = 0.05_RK
     175             :         type(Timer_type)    :: Timer
     176           1 :         type(Err_type)      :: Err
     177             : 
     178           1 :         Timer = Timer_type(Err)
     179           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
     180           1 :         call sleep(seconds=seconds,Err=Err)
     181           1 :         assertion = .not. Err%occurred; if (.not. assertion) return
     182           1 :         assertion = assertion .and. Timer%delta() > 0.9_RK * seconds
     183             : 
     184             :         ! LCOV_EXCL_START
     185             :         if (Test%isDebugMode .and. .not. assertion) then
     186             :             write(Test%outputUnit,"(*(g0))")
     187             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%start: ", Timer%Count%start
     188             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%rate : ", Timer%Count%rate
     189             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%max  : ", Timer%Count%max
     190             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%stop : ", Timer%Count%stop
     191             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%total: ", Timer%Count%total
     192             :             write(Test%outputUnit,"(*(g0))")   "Timer%Count%delta: ", Timer%Count%delta
     193             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%start : ", Timer%Time%start
     194             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%stop  : ", Timer%Time%stop
     195             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%total : ", Timer%Time%total
     196             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%delta : ", Timer%Time%delta
     197             :             write(Test%outputUnit,"(*(g0))")   "Timer%period     : ", Timer%period
     198             :             write(Test%outputUnit,"(*(g0))")   "Timer%Time%unit  : ", Timer%Time%unit
     199             :             write(Test%outputUnit,"(*(g0))")
     200             :         end if
     201             :         ! LCOV_EXCL_STOP
     202             : 
     203           2 :     end function test_getTimeSinceLastCall_1
     204             : 
     205             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     206             : 
     207             : end module Test_Timer_mod ! LCOV_EXCL_LINE

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