C Library Functions  - unit_test (3)

NAME

unit_test(3f) - [M_framework__verify] report if logical expression is true or false, optionally call command and/or stop program. (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
Author
License

SYNOPSIS

subroutine unit_test(name,expression,msg,g1,g2,g3,g4,g5,g6,g7,g8,g9,& & ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,only_on_fail)

    character(len=*),intent(in) :: name
    logical,intent(in) :: expression
    class(*),intent(in),optional :: msg,g1,g2,g3,g4,g5,g6,g7,g8,g9,&
    & ga,gb,gc,gd,ge,gf,gg,gh,gi,gj
    logical,intent(in),optional :: only_on_fail

DESCRIPTION

unit_test(3f) tests the expression and displays a message composed of the generic intrinsic values msg, and g1 thorough gj. Additionally, if the expression is false
o if unit_test_mode(command) is not blank calls the specified shell command
      $COMMAND name="NAME" type="check" passed="passed|failed" ...
      msg="all messages"

o if keep_going = .false. stop the program on a failed test

OPTIONS

NAME
  the unit test name
EXPRESSION
  the logical expression to evaluate
msg,g1...gj
  optional message to display when performing test, composed of any scalar intrinsics of type INTEGER, REAL, DOUBLEPRECISION, COMPLEX, LOGICAL, or CHARACTER. A space is placed between each value.
wordy
  If .false. The message MSG is only displayed if the expression is .false. . Must be used as a keyword. Default is .true. .

EXAMPLES

Sample program:

      program demo_unit_test
      use M_framework, only: &
         & unit_test_mode,     &
         & unit_test_start,    &
         & unit_test,          &
         & unit_test_end,      &
         & unit_test_stop
      use M_framework, only: almost

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

call unit_test_mode(keep_going=.true.,debug=.false.,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 ,’ if big enough’) call unit_test(’myroutine’, x < 100 ,’ 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) , & & ’fail if any negative values in array ARR’) call unit_test(’myroutine’, all(arr < 100) , & & ’fail unless all values are less than 100 in array ARR’)

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

call unit_test_stop()

end program demo_unit_test

Results:

 Sample output (varies with what optional command or modes is used):

>check_start: myroutine START : >check: myroutine SUCCESS : if big enough >check: myroutine SUCCESS : if small enough >*almost* for values 1.00000000 1.00010002 agreement of 3.99997139 ... >digits out of requested 3.90000010 >check: myroutine SUCCESS : >*almost* for values 10.0000000 10.0010004 agreement of 3.99986792 ... >digits out of requested 3.90000010 >check: myroutine SUCCESS : >*almost* for values 100.000000 100.010002 agreement of 3.99995065 ... >digits out of requested 3.90000010 >check: myroutine SUCCESS : >check: myroutine SUCCESS : fail if any negative ... >values in array ARR >check: myroutine SUCCESS : fail unless all values ... >are less than 100 in array ARR >check_end: myroutine PASSED : GOOD:7 BAD: ... >0 DURATION:00000000294709: checks on "myroutine" all passed >check_stop: TALLY PASSED : GOOD:7 BAD: ... >0 DURATION:00000000267059

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 unit_test (3) July 22, 2023
Generated by manServer 1.08 from fd8f0b61-8093-4ce6-9077-fd75e324885b using man macros.