|
| 1 | +program test_math_is_close |
| 2 | + |
| 3 | + call test_math_is_close_real |
| 4 | + call test_math_is_close_complex |
| 5 | + print *, "All tests in `test_math_is_close` passed." |
| 6 | + |
| 7 | +contains |
| 8 | + |
| 9 | + subroutine test_math_is_close_real |
| 10 | + use stdlib_math, only: is_close |
| 11 | + use stdlib_error, only: check |
| 12 | + |
| 13 | + call check(is_close(2.5, 2.5, rtol=1.0e-5), msg="is_close(2.5, 2.5, rtol=1.0e-5) failed.") |
| 14 | + call check(all(is_close([2.5, 3.2], [2.5, 10.0], rtol=1.0e-5)), & |
| 15 | + msg="all(is_close([2.5, 3.2], [2.5, 10.0], rtol=1.0e-5)) failed (expected).", warn=.true.) |
| 16 | + call check(all(is_close(reshape([2.5, 3.2, 2.2, 1.0], [2, 2]), reshape([2.5, 3.2001, 2.25, 1.1], [2, 2]), & |
| 17 | + atol=1.0e-5, rtol=0.1)), & |
| 18 | + msg="all(is_close(reshape([2.5, 3.2, 2.2, 1.0],[2,2]), reshape([2.5, 3.2001, 2.25, 1.1],[2,2]), & |
| 19 | + &rtol=1.0e-5, atol=0.1)) failed.") |
| 20 | + |
| 21 | + end subroutine test_math_is_close_real |
| 22 | + |
| 23 | + subroutine test_math_is_close_complex |
| 24 | + use stdlib_math, only: is_close |
| 25 | + use stdlib_error, only: check |
| 26 | + |
| 27 | + call check(is_close((2.5,1.2), (2.5,1.2), rtol=1.0e-5), & |
| 28 | + msg="is_close((2.5,1.2), (2.5,1.2), rtol=1.0e-5) failed.") |
| 29 | + call check(all(is_close([(2.5,1.2), (3.2,1.2)], [(2.5,1.2), (10.0,1.2)], rtol=1.0e-5)), & |
| 30 | + msg="all(is_close([(2.5,1.2), (3.2,1.2)], [(2.5,1.2), (10.0,1.2)], rtol=1.0e-5)) failed (expected).", & |
| 31 | + warn=.true.) |
| 32 | + call check(all(is_close(reshape([(2.5,1.2009), (3.2,1.199999)], [1, 2]), reshape([(2.4,1.2009), (3.15,1.199999)], [1, 2]), & |
| 33 | + atol=1.0e-5, rtol=0.1)), & |
| 34 | + msg="all(is_close(reshape([(2.5,1.2009), (3.2,1.199999)], [1, 2]), & |
| 35 | + &reshape([(2.4,1.2009), (3.15,1.199999)], [1, 2]), & |
| 36 | + &rtol=1.0e-5, atol=0.1)) failed.") |
| 37 | + |
| 38 | + end subroutine test_math_is_close_complex |
| 39 | + |
| 40 | +end program test_math_is_close |
0 commit comments