unit_check(3f) - [M_verify] if logical expression is false, call command "goodbad NAME bad" and stop program by default (LICENSE:PD)
Synopsis
Description
Options
Examples
Author
License
subroutine unit_check(name,expression,msg,msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9)
character(len=*),intent(in) :: name logical,intent(in) :: expression class(*),intent(in),optional :: msg,msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9
unit_check(3f) tests the expression and if it is false, calls the shell command
goodbad NAME badand stops the program.
NAME the unit test name passed on to the goodbad(1) command EXPRESSION the logical expression to evaluate MSG,MSG1...MSG9 optional message to display when performing test, composed of any scalar intrinsics of type INTEGER, REAL, DOUBLEPRECISION, COMPLEX, LOGICAL, or CHARACTER, with a space placed between each value.
Sample program:
program demo_unit_check use M_verify, only: unit_check use M_verify, only: unit_check_start use M_verify, only: unit_check_done use M_verify, only: almostSample output (varies with what goodbad(1) command is used):!!use M_verify, only: unit_check_keep_going ! default is unit_check_keep_going=.false. !!use M_verify, only: debug ! default is .false. !!use M_verify, only: unit_check_command ! default is unit_check_command=; was goodbad
implicit none integer :: i integer :: x integer,allocatable :: arr(:) real,allocatable :: arr1(:) real,allocatable :: arr2(:)
!!unit_check_command= x=10 arr1=[1.0,10.0,100.0] arr2=[1.0001,10.001,100.01] call unit_check_start(myroutine)
call unit_check(myroutine, x > 3 ,test if big enough) call unit_check(myroutine, x < 100 ,test if small enough)
do i=1,size(arr1) call unit_check(myroutine, almost(arr1(i),arr2(i),3.9,verbose=.true.) ) enddo
arr=[10,20,30] call unit_check(myroutine, .not.any(arr < 0) ,test if any negative values in array ARR) call unit_check(myroutine, all(arr < 100) ,test if all values less than 100 in array ARR)
call unit_check_done(myroutine,msg=checks on "myroutine" all passed)
end program demo_unit_check
unit_check: myroutine SUCCESS:test if big enough unit_check: myroutine SUCCESS:test if small enough unit_check: myroutine SUCCESS:test if any negative values in array ARR unit_check: myroutine SUCCESS:test if all values less than 100 in array ARR *almost* for values 1.00000000 1.00010002 agreement of 3.99997139 digits out of requested 3.90000010 *almost* for values 10.0000000 10.0010004 agreement of 3.99986792 digits out of requested 3.90000010 *almost* for values 100.000000 100.010002 agreement of 3.99995065 digits out of requested 3.90000010 unit_check_good: myroutine PASSED:checks on "myroutine" all passed
John S. Urban
Public Domain