Skip to content

Commit

Permalink
add tests, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bena-nasa committed Sep 9, 2024
1 parent f6599cc commit 2540730
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions generic3g/tests/Test_FixedLevelsVerticalGrid.pf
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,20 @@ contains

end subroutine test_equals

@test
subroutine test_not_equals()
type(FixedLevelsVerticalGrid) :: vgrid1, vgrid2, vgrid3

real, parameter :: levels1(*) = [1.,5.,7.]
real, parameter :: levels2(*) = [.01,4.]

vgrid1 = FixedLevelsVerticalGrid(standard_name='air_pressure', units='Pa', levels=levels1)
vgrid2 = FixedLevelsVerticalGrid(standard_name='air_pressure', units='mb', levels=levels1)
vgrid3 = FixedLevelsVerticalGrid(standard_name='air_pressure', units='Pa', levels=levels2)
@assert_that(vgrid1 /= vgrid2, is(.true.))
@assert_that(vgrid1 /= vgrid3, is(.true.))

end subroutine test_not_equals


end module Test_FixedLevelsVerticalGrid
6 changes: 4 additions & 2 deletions generic3g/vertical/FixedLevelsVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@ logical function can_connect_to(this, src, rc)
_UNUSED_DUMMY(src)
end function can_connect_to

logical function equal_FixedLevelsVerticalGrid(a, b) result(equal)
impure elemental logical function equal_FixedLevelsVerticalGrid(a, b) result(equal)
type(FixedLevelsVerticalGrid), intent(in) :: a, b

equal = a%standard_name == b%standard_name
if (.not. equal) return
equal = a%units == b%units
if (.not. equal) return
equal = size(a%levels) == size(b%levels)
if (.not. equal) return
equal = all(a%levels == b%levels)
end function equal_FixedLevelsVerticalGrid

logical function not_equal_FixedLevelsVerticalGrid(a, b) result(not_equal)
impure elemental logical function not_equal_FixedLevelsVerticalGrid(a, b) result(not_equal)
type(FixedLevelsVerticalGrid), intent(in) :: a, b

not_equal = .not. (a==b)
Expand Down

0 comments on commit 2540730

Please sign in to comment.