assert_isclose_real64 Function

public function assert_isclose_real64(got, expect, test_name, rtol, print_result) result(test_pass)

Asserts that two real64 values coincide to a given relative tolerance

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: got

The value to be tested

real(kind=real64), intent(in) :: expect

The expected value

character(len=*), intent(in) :: test_name

Name of the test being run

real(kind=real64), intent(in), optional :: rtol

Optional relative tolerance (defaults to 1e-5)

logical, intent(in), optional :: print_result

Optionally print test result to screen (defaults to .true.)

Return Value logical

Did the assertion pass?


Source Code

    function assert_isclose_real64(got, expect, test_name, rtol, print_result) result(test_pass)

      character(len=*), intent(in) :: test_name !! Name of the test being run
      real(kind=real64), intent(in) :: got !! The value to be tested
      real(kind=real64), intent(in) :: expect !! The expected value
      real(kind=real64), intent(in), optional :: rtol !! Optional relative tolerance (defaults to 1e-5)
      logical, intent(in), optional :: print_result !! Optionally print test result to screen (defaults to .true.)

      logical :: test_pass !! Did the assertion pass?

      character(len=80) :: message

      real(kind=real64) :: relative_error
      real(kind=real64) :: rtol_value
      logical :: print_result_value

      if (.not. present(rtol)) then
        rtol_value = 1e-5
      else
        rtol_value = rtol
      end if

      if (.not. present(print_result)) then
        print_result_value = .true.
      else
        print_result_value = print_result
      end if

      test_pass = (abs(got - expect) <= rtol_value * abs(expect))

      if (print_result_value) then
        write(message,'("relative tolerance = ", E11.4)') rtol_value
        call test_print(test_name, message, test_pass)
      end if

    end function assert_isclose_real64