|
GRASP rci-qed
|
Various handy routines useful for writing unit tests. More...
Data Types | |
| interface | test_isequal |
Functions/Subroutines | |
| real(real64) function | reldiff (a, b) |
Calculate the relative difference of a and b. More... | |
| logical function | within_tolerance (a, b, relative_tolerance) |
Checks if the difference of a and b are within the tolerance relative to \(\max(|a|,|b|)\). More... | |
| subroutine | test_isequal_real64 (test_passed, which, a, b, relative_tolerance) |
| Tests if two floating point values are the same withing the specified relative tolerance. More... | |
| subroutine | test_isequal_logical (test_passed, which, a, b) |
| Tests if two logical values are equal. More... | |
| subroutine | test_isequal_integer (test_passed, which, a, b) |
| Tests if two integer values are equal. More... | |
| subroutine | test_isequal_atol (test_passed, which, a, b, absolute_tolerance) |
| Tests if two floating point values are the same withing the specified absolute tolerance. More... | |
Various handy routines useful for writing unit tests.
| real(real64) function grasptest_testing::reldiff | ( | real(real64), intent(in) | a, |
| real(real64), intent(in) | b | ||
| ) |
Calculate the relative difference of a and b.
The relative difference is defined as:
\[ \frac{|a-b|}{\max(|a|, |b|)} \]
| a,b | Input values. |
a and b. | subroutine grasptest_testing::test_isequal_atol | ( | logical, intent(inout) | test_passed, |
| character(*), intent(in) | which, | ||
| real(real64), intent(in) | a, | ||
| real(real64), intent(in) | b, | ||
| real(real64), intent(in) | absolute_tolerance | ||
| ) |
Tests if two floating point values are the same withing the specified absolute tolerance.
Specifically, it tests that
\[ |a-b| < \sigma \]
where \(\sigma\) is the specified absolute tolerance.
If the test fails, test_passed gets set to .false., but the value is unchanged if the tests pass. This allows for the pattern where the test function is called multiple times before checking if any of the tests failed:
On failure, a message gets printed into the standard output that a test failed, which also includes the which string, allowing for the failed test to be identified easily.
| test_passed | Gets set to .false. if the test fails, and is left unchanged otherwise. |
| which | A string that identifies the test. |
| a,b | Values to be compared. |
| absolute_tolerance | The absolute tolerance \(\sigma\). |

| subroutine grasptest_testing::test_isequal_integer | ( | logical, intent(inout) | test_passed, |
| character(*), intent(in) | which, | ||
| integer, intent(in) | a, | ||
| integer, intent(in) | b | ||
| ) |
Tests if two integer values are equal.
| subroutine grasptest_testing::test_isequal_logical | ( | logical, intent(inout) | test_passed, |
| character(*), intent(in) | which, | ||
| logical, intent(in) | a, | ||
| logical, intent(in) | b | ||
| ) |
Tests if two logical values are equal.
| subroutine grasptest_testing::test_isequal_real64 | ( | logical, intent(inout) | test_passed, |
| character(*), intent(in) | which, | ||
| real(real64), intent(in) | a, | ||
| real(real64), intent(in) | b, | ||
| real(real64), intent(in) | relative_tolerance | ||
| ) |
Tests if two floating point values are the same withing the specified relative tolerance.
Specifically, it tests that
\[ \frac{|a-b|}{\max(|a|, |b|)} < \sigma \]
where \(\sigma\) is the specified relative tolerance.
If the test fails, test_passed gets set to .false., but the value is unchanged if the tests pass. This allows for the pattern where the test function is called multiple times before checking if any of the tests failed:
On failure, a message gets printed into the standard output that a test failed, which also includes the which string, allowing for the failed test to be identified easily.
| test_passed | Gets set to .false. if the test fails, and is left unchanged otherwise. |
| which | A string that identifies the test. |
| a,b | Values to be compared. |
| relative_tolerance | The relative tolerance \(\sigma\). |

| logical function grasptest_testing::within_tolerance | ( | real(real64), intent(in) | a, |
| real(real64), intent(in) | b, | ||
| real(real64), intent(in) | relative_tolerance | ||
| ) |
Checks if the difference of a and b are within the tolerance relative to \(\max(|a|,|b|)\).
| a,b | Values to be checked. |
| relative_tolerance | Relative tolerance \(\sigma\). |
1.8.13