C Library Functions  - unit_test (3)

NAME

unit_test(3f) - [M_verify] if logical expression is false, call command "goodbad NAME bad" and stop program by default (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
Author
License

SYNOPSIS

subroutine unit_test(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

DESCRIPTION

unit_test(3f) tests the expression and if it is false, calls the shell command

        goodbad NAME bad

and stops the program.

OPTIONS

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.

EXAMPLES

Sample program:

   program demo_unit_test
   use M_verify, only: unit_test
   use M_verify, only: unit_test_start
   use M_verify, only: unit_test_done
   use M_verify,  only: almost

!!use M_verify, only: unit_test_keep_going ! default is unit_test_keep_going=.false. !!use M_verify, only: debug ! default is .false. !!use M_verify, only: unit_test_command ! default is unit_test_command=’’; was ’goodbad’

implicit none integer :: i integer :: x integer,allocatable :: arr(:) real,allocatable :: arr1(:) real,allocatable :: arr2(:)

!!unit_test_command=’’ x=10 arr1=[1.0,10.0,100.0] arr2=[1.0001,10.001,100.01] call unit_test_start(’myroutine’)

call unit_test(’myroutine’, x > 3 ,’test if big enough’) call unit_test(’myroutine’, x < 100 ,’test if small enough’)

do i=1,size(arr1) call unit_test(’myroutine’, almost(arr1(i),arr2(i),3.9,verbose=.true.) ) enddo

arr=[10,20,30] call unit_test(’myroutine’, .not.any(arr < 0) ,’test if any negative values in array ARR’) call unit_test(’myroutine’, all(arr < 100) ,’test if all values less than 100 in array ARR’)

call unit_test_done(’myroutine’,msg=’checks on "myroutine" all passed’)

end program demo_unit_test

Sample output (varies with what goodbad(1) command is used):

   unit_test:      myroutine        SUCCESS:test if big enough
   unit_test:      myroutine        SUCCESS:test if small enough
   unit_test:      myroutine        SUCCESS:test if any negative values in array ARR
   unit_test:      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_test_good: myroutine        PASSED:checks on "myroutine" all passed

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 unit_test (3) June 29, 2025
Generated by manServer 1.08 from 03d849e3-97a9-444b-ac41-2e4b4db724bb using man macros.