Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with stdlib_sorting #428

Merged
merged 3 commits into from
Jun 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/stdlib_sorting_ord_sort.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ contains
do j=1, size(array, kind=int_size)-1
key = array(j)
i = j - 1
do while( i >= 0 .and. array(i) ${signt}$ key )
do while( i >= 0 )
if ( array(i) ${signoppt}$= key ) exit
array(i+1) = array(i)
i = i - 1
end do
Expand Down Expand Up @@ -518,7 +519,8 @@ contains
do j=1, size(array, kind=int_size)-1
key = array(j)
i = j - 1
do while( i >= 0 .and. array(i) ${signt}$ key )
do while( i >= 0 )
if ( array(i) ${signoppt}$= key ) exit
array(i+1) = array(i)
i = i - 1
end do
Expand Down
6 changes: 4 additions & 2 deletions src/stdlib_sorting_sort_index.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ contains
key = array(j)
key_index = index(j)
i = j - 1
do while( i >= 0 .and. array(i) > key )
do while( i >= 0 )
if ( array(i) <= key ) exit
array(i+1) = array(i)
index(i+1) = index(i)
i = i - 1
Expand Down Expand Up @@ -585,7 +586,8 @@ contains
key = array(j)
key_index = index(j)
i = j - 1
do while( i >= 0 .and. array(i) > key )
do while( i >= 0 )
if ( array(i) <= key ) exit
array(i+1) = array(i)
index(i+1) = index(i)
i = i - 1
Expand Down
34 changes: 30 additions & 4 deletions src/tests/sorting/test_sorting.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ program test_sorting
integer(int32), parameter :: char_size = 26**4
integer(int32), parameter :: string_size = 26**3
integer(int32), parameter :: block_size = test_size/6
integer, parameter :: repeat = 8
integer, parameter :: repeat = 1

integer(int32) :: &
blocks(0:test_size-1), &
Expand Down Expand Up @@ -179,7 +179,9 @@ program test_sorting
subroutine test_int_ord_sorts( ltest )
logical, intent(out) :: ltest

logical :: ldummy
integer(int64) :: i
integer, allocatable :: d1(:)
logical :: ldummy

ltest = .true.

Expand All @@ -202,6 +204,13 @@ subroutine test_int_ord_sorts( ltest )
call test_int_ord_sort( rand10, "Random 10", ldummy )
ltest = (ltest .and. ldummy)

!triggered an issue in insertion_sort
d1 = [10, 2, -3, -4, 6, -6, 7, -8, 9, 0, 1, 20]
call ord_sort( d1 )
call verify_sort( d1, ldummy, i )
ltest = (ltest .and. ldummy)


end subroutine test_int_ord_sorts


Expand Down Expand Up @@ -418,7 +427,9 @@ end subroutine test_string_ord_sort
subroutine test_int_sorts( ltest )
logical, intent(out) :: ltest

logical :: ldummy
integer(int64) :: i
integer, allocatable :: d1(:)
logical :: ldummy

ltest = .true.

Expand All @@ -441,6 +452,12 @@ subroutine test_int_sorts( ltest )
call test_int_sort( rand10, "Random 10", ldummy )
ltest = (ltest .and. ldummy)

!triggered an issue in insertion
d1 = [10, 2, -3, -4, 6, -6, 7, -8, 9, 0, 1, 20]
call sort( d1 )
call verify_sort( d1, ldummy, i )
ltest = (ltest .and. ldummy)

end subroutine test_int_sorts

subroutine test_int_sort( a, a_name, ltest )
Expand Down Expand Up @@ -623,7 +640,10 @@ end subroutine test_string_sort
subroutine test_int_sort_indexes( ltest )
logical, intent(out) :: ltest

logical :: ldummy
integer(int64) :: i
integer(int32), allocatable :: d1(:)
integer(int64), allocatable :: index(:)
logical :: ldummy

ltest = .true.

Expand All @@ -646,6 +666,12 @@ subroutine test_int_sort_indexes( ltest )
call test_int_sort_index( rand10, "Random 10", ldummy )
ltest = (ltest .and. ldummy)

d1 = [10, 2, -3, -4, 6, -6, 7, -8, 9, 0, 1, 20]
allocate( index(size(d1)) )
call sort_index( d1, index )
call verify_sort( d1, ldummy, i )
ltest = (ltest .and. ldummy)

end subroutine test_int_sort_indexes

subroutine test_int_sort_index( a, a_name, ltest )
Expand Down