unit_test_cx2 Subroutine

private subroutine unit_test_cx2(this, res, expected, tol, msg)

Type Bound

unit_test

Arguments

Type IntentOptional Attributes Name
class(unit_test), intent(inout) :: this
complex(kind=rk), intent(in), dimension(:,:) :: res
complex(kind=rk), intent(in), dimension(:,:) :: expected
real(kind=rk), intent(in), optional :: tol
character(len=*), intent(in), optional :: msg

Calls

proc~~unit_test_cx2~~CallsGraph proc~unit_test_cx2 forunittest::unit_test%unit_test_cx2 proc~print_msg forunittest::unit_test%print_msg proc~unit_test_cx2->proc~print_msg colorize colorize proc~print_msg->colorize

Called by

proc~~unit_test_cx2~~CalledByGraph proc~unit_test_cx2 forunittest::unit_test%unit_test_cx2 none~check forunittest::unit_test%check none~check->proc~unit_test_cx2 program~demo demo program~demo->none~check program~test test program~test->none~check

Source Code

   subroutine unit_test_cx2(this, res, expected, tol, msg)
      class(unit_test), intent(inout) :: this
      complex(rk), intent(in), dimension(:,:) :: res, expected
      real(rk), intent(in), optional :: tol
      character(*), intent(in), optional :: msg
      logical :: condition
      real(rk) :: rel_err_re, rel_err_im

      if (present(msg)) then
         this%msg = msg
      else
         this%msg = 'forunittest'
      end if

      if (norm2(real(expected,rk))<tiny(0.0_rk)) then
         rel_err_re = norm2(real(res,rk)-real(expected,rk))
      else
         rel_err_re = norm2(real(res,rk)-real(expected,rk))/norm2(real(expected,rk))
      end if

      if (norm2(aimag(expected))<tiny(0.0_rk)) then
         rel_err_im = norm2(aimag(res)-aimag(expected))
      else
         rel_err_im = norm2(aimag(res)-aimag(expected))/norm2(aimag(expected))
      end if

      if (present(tol)) then
         condition = (rel_err_re < tol) .and. (rel_err_im < tol)
      else
         condition = (rel_err_re <= tiny(0.0_rk)) .and. (rel_err_im <= tiny(0.0_rk))
      end if

      call this%print_msg(condition)
   end subroutine unit_test_cx2