Skip to content

Commit

Permalink
add test for strings with different lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvesz committed Sep 21, 2024
1 parent 4b3a473 commit 7c5763c
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions test/math/test_stdlib_math.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,48 @@ contains

subroutine test_swap_str(error)
type(error_type), allocatable, intent(out) :: error
character(5) :: x(2), y(2)

x = ['abcde','fghij']
y = ['fghij','abcde']
block
character(5) :: x(2), y(2)

x = ['abcde','fghij']
y = ['fghij','abcde']

call swap(x,y)

call check(error, all( x == ['fghij','abcde'] ) )
if (allocated(error)) return
call check(error, all( y == ['abcde','fghij'] ) )
if (allocated(error)) return
call swap(x,y)
call check(error, all( x == ['fghij','abcde'] ) )
if (allocated(error)) return
call check(error, all( y == ['abcde','fghij'] ) )
if (allocated(error)) return

! check self swap
call swap(x,x)

call check(error, all( x == ['fghij','abcde'] ) )
if (allocated(error)) return
! check self swap
call swap(x,x)

call check(error, all( x == ['fghij','abcde'] ) )
if (allocated(error)) return
end block

block
character(4) :: x
character(6) :: y

x = 'abcd'
y = 'efghij'
call swap(x,y)

call check(error, x == 'efgh' )
if (allocated(error)) return
call check(error, y(1:6) == 'abcd ' )
if (allocated(error)) return

x = 'abcd'
y = 'efghij'
call swap(x,y(1:4))

call check(error, x == 'efgh' )
if (allocated(error)) return
call check(error, y == 'abcdij' )
if (allocated(error)) return
end block
end subroutine test_swap_str

subroutine test_swap_stt(error)
Expand Down

0 comments on commit 7c5763c

Please sign in to comment.