Skip to content

Commit

Permalink
added the fotran-testanything code
Browse files Browse the repository at this point in the history
from dennisdjensen
https://github.com/dennisdjensen/fortran-testanything
license included in this commit.
renamed test.f08 to test.f90 because *.f90 is what we have mkmf looking for

updated buildfunctions to include the fortran-testanything code for developer tests only
removed the local threed_model_mod.f90 (using the template model path like other developer tests)
  • Loading branch information
hkershaw-brown committed Nov 1, 2024
1 parent 6c73b04 commit 8dabf8d
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 299 deletions.
4 changes: 4 additions & 0 deletions build_templates/buildfunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ done
function dartbuild() {

local program
local devlibs

if [ $dev_test -eq 0 ]; then
devlibs=""
#look in $program directory for {main}.f90
if [ $1 == "obs_diag" ]; then
program=$DART/assimilation_code/programs/obs_diag/$LOCATION
Expand All @@ -235,11 +237,13 @@ if [ $dev_test -eq 0 ]; then
else
# For developer tests {main}.f90 is in developer_tests
program=$DART/developer_tests/$TEST/$1.f90
devlibs=$DART/developer_tests/contrib/fortran-testanything
fi

$DART/build_templates/mkmf -x -a $DART $m -p $1 \
$dartsrc \
$EXTRA \
$devlibs \
$program
}

Expand Down
14 changes: 14 additions & 0 deletions developer_tests/contrib/fortran-testanything/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright 2015 Dennis Decker Jensen

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

24 changes: 24 additions & 0 deletions developer_tests/contrib/fortran-testanything/is_i.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! Template parameter: wp (working precision)
! Template free identifiers: testline, tests
subroutine is(got, expected, msg)
integer(kind=wp), intent(in) :: got, expected
character(len=*), intent(in), optional :: msg
character(len=:), allocatable :: testmsg, idmsg
character(len=120) gotmsg, expectedmsg
logical good

if (present(msg)) then
allocate(character(len=len_trim(msg)+20) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,A,A)') 'Failed test: "', trim(msg), '"'
testmsg = trim(msg)
else
allocate(character(len=30) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,I0)') 'Failed test no. ', tests + 1
testmsg = ""
end if
write (unit=gotmsg, fmt='(A,I0)') ' got: ', got
write (unit=expectedmsg, fmt='(A,I0)') 'expected: ', expected

good = got == expected
call testline(good, testmsg, idmsg, gotmsg, expectedmsg)
end
83 changes: 83 additions & 0 deletions developer_tests/contrib/fortran-testanything/is_r.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
! Template parameter: wp (working precision)
! Template free identifiers: testline, tests
subroutine isabs(got, expected, eps, msg)
real(kind=wp), intent(in) :: got, expected
character(len=*), intent(in), optional :: msg
real(kind=wp), intent(in), optional :: eps
character(len=:), allocatable :: testmsg, idmsg
character(len=120) gotmsg, expectedmsg
real(kind=wp) tolerance
logical good

if (present(msg)) then
allocate(character(len=len_trim(msg)+20) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,A,A)') 'Failed test: "', trim(msg), '"'
testmsg = trim(msg)
else
allocate(character(len=30) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,I0)') 'Failed test no. ', tests + 1
testmsg = ""
end if
write (unit=gotmsg, fmt='(A,G0)') ' got: ', got
write (unit=expectedmsg, fmt='(A,G0)') 'expected: ', expected

if (present(eps)) then
tolerance = eps
else
tolerance = epsilon(got)
end if
! eps = 0.5e-10_wp
! Absolute accuracy within the 10 least significant digits
good = abs(got - expected) < tolerance
call testline(good, testmsg, idmsg, gotmsg, expectedmsg)
end

subroutine isrel(got, expected, eps, msg)
real(kind=wp), intent(in) :: got, expected
character(len=*), intent(in), optional :: msg
real(kind=wp), intent(in), optional :: eps
real(kind=wp) tolerance

! eps = (abs(a) + abs(b)) * 0.5e-10_wp
! Relative accuracy within the 10 most significant digits
tolerance = (abs(got) + abs(expected))
if (present(eps)) then
tolerance = tolerance * eps
else
tolerance = tolerance * epsilon(got)
end if
call isabs(got, expected, tolerance, msg)
end

subroutine isnear(got, expected, eps, msg)
real(kind=wp), intent(in) :: got, expected
character(len=*), intent(in), optional :: msg
real(kind=wp), intent(in), optional :: eps
character(len=:), allocatable :: testmsg, idmsg
character(len=120) gotmsg, expectedmsg
real(kind=wp) tolerance
logical good

if (present(msg)) then
allocate(character(len=len_trim(msg)+20) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,A,A)') 'Failed test: "', trim(msg), '"'
testmsg = trim(msg)
else
allocate(character(len=30) :: testmsg, idmsg)
write (unit=idmsg, fmt='(A,I0)') 'Failed test no. ', tests + 1
testmsg = ""
end if
write (unit=gotmsg, fmt='(A,G0)') ' got: ', got
write (unit=expectedmsg, fmt='(A,G0)') 'expected: ', expected

if (present(eps)) then
tolerance = eps
else
tolerance = epsilon(got) ! minimun eps for which 1 + eps /= 1
end if
! Relative accuracy around 1.0_wp
! Semantics of isnear means using <=, and not <, c.f. epsilon(got)
good = abs(got / expected - 1.0_wp) <= tolerance
call testline(good, testmsg, idmsg, gotmsg, expectedmsg)
end

Loading

0 comments on commit 8dabf8d

Please sign in to comment.