From 933a367956c02f8ca9fed876f4ec8973be9317d1 Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 10 Oct 2021 21:44:08 +0530 Subject: [PATCH 1/7] resolved inserting 0 lengthed slist in list bug --- src/stdlib_stringlist_type.f90 | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/stdlib_stringlist_type.f90 b/src/stdlib_stringlist_type.f90 index 78cfb69d3..8aade5a1a 100644 --- a/src/stdlib_stringlist_type.f90 +++ b/src/stdlib_stringlist_type.f90 @@ -642,23 +642,27 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist ) type(stringlist_type), intent(in) :: slist integer :: i - integer :: work_idxn, idxnew + integer :: work_idxn, inew integer :: pre_length, post_length - work_idxn = idxn pre_length = slist%len() - call insert_before_empty_positions( list, work_idxn, pre_length ) - post_length = slist%len() + if (pre_length > 0) then + work_idxn = idxn - do i = 1, min( work_idxn - 1, pre_length ) - idxnew = work_idxn + i - 1 - list%stringarray(idxnew) = slist%stringarray(i) - end do + call insert_before_engine( list, work_idxn, pre_length ) + post_length = slist%len() - do i = work_idxn + post_length - pre_length, post_length - idxnew = work_idxn + i - post_length + pre_length - 1 - list%stringarray(idxnew) = slist%stringarray(i) - end do + inew = work_idxn + do i = 1, min( work_idxn - 1, pre_length ) + list%stringarray(inew) = slist%stringarray(i) + inew = inew + 1 + end do + + do i = work_idxn + post_length - pre_length, post_length + list%stringarray(inew) = slist%stringarray(i) + inew = inew + 1 + end do + end if end subroutine insert_before_stringlist_int_impl From ea46f1941eace5a3b1a7567b5b70f2f21cf163e9 Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 10 Oct 2021 21:45:48 +0530 Subject: [PATCH 2/7] changed name --- src/stdlib_stringlist_type.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stringlist_type.f90 b/src/stdlib_stringlist_type.f90 index 8aade5a1a..c476be548 100644 --- a/src/stdlib_stringlist_type.f90 +++ b/src/stdlib_stringlist_type.f90 @@ -649,7 +649,7 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist ) if (pre_length > 0) then work_idxn = idxn - call insert_before_engine( list, work_idxn, pre_length ) + call insert_before_empty_positions( list, work_idxn, pre_length ) post_length = slist%len() inew = work_idxn From 875def463ddd79c73e992737160d3ca05e29ec74 Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sat, 16 Oct 2021 00:30:31 +0530 Subject: [PATCH 3/7] added test cases for inserting a list in itself --- src/tests/stringlist/test_insert_at.f90 | 74 ++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/src/tests/stringlist/test_insert_at.f90 b/src/tests/stringlist/test_insert_at.f90 index 231ac0e9c..6c150826b 100644 --- a/src/tests/stringlist/test_insert_at.f90 +++ b/src/tests/stringlist/test_insert_at.f90 @@ -4,6 +4,7 @@ module test_insert_at use stdlib_string_type, only: string_type, operator(//), operator(==) use stdlib_stringlist_type, only: stringlist_type, fidx, bidx, list_head, list_tail, operator(==) use stdlib_strings, only: to_string + use stdlib_optval, only: optval implicit none contains @@ -351,24 +352,82 @@ subroutine test_constructor end subroutine test_constructor + subroutine test_insert_at_same_list + type(stringlist_type) :: work_list + type(stringlist_type) :: temp_list + integer :: i, j + integer, parameter :: first = -100 + integer, parameter :: last = 100 + integer, parameter :: stride = 4 + + write (*,*) "test_insert_at_same_list: Starting work_list!" + + call work_list%insert_at( list_head, work_list ) + call work_list%insert_at( list_tail, work_list ) + + do j = -10, 10 + call work_list%insert_at( fidx(j), work_list ) + call work_list%insert_at( bidx(j), work_list ) + + end do + + call compare_list( work_list, 0, 0, 13 ) + + do j = first, last + call work_list%insert_at( list_tail, string_type( to_string(j) ) ) + end do + + temp_list = work_list + call work_list%insert_at( list_head, work_list ) + call compare_list( work_list, first, last + 1, 14, to=last - first + 1 ) + call compare_list( work_list, first, last + 1, 15, from=last - first + 2 ) + + work_list = temp_list + call work_list%insert_at( list_tail, work_list ) + call compare_list( work_list, first, last + 1, 16, to=last - first + 1 ) + call compare_list( work_list, first, last + 1, 17, from=last - first + 2 ) + + work_list = temp_list + call compare_list( work_list, first, last + 1, 18 ) + + do j = 1, last - first + 2 + temp_list = work_list + call temp_list%insert_at( fidx(j), temp_list ) + + call compare_list( temp_list, first, first + j - 1, 19, to=j - 1) + call compare_list( temp_list, first, last + 1, 20, from=j, to=j + last - first) + call compare_list( temp_list, first + j - 1, last + 1, 21, from=j + last - first + 1) + + end do + + end subroutine test_insert_at_same_list + ! compares input stringlist 'list' with an array of consecutive integers ! array is 'first' inclusive and 'last' exclusive - subroutine compare_list(list, first, last, call_number) + subroutine compare_list(list, first, last, call_number, from, to) type(stringlist_type), intent(in) :: list integer, intent(in) :: first, last, call_number - integer :: i, j + integer, intent(in), optional :: from, to + integer :: i, j, k, work_from, work_to, length + + length = list%len() + work_from = optval( from, 1 ) + work_to = optval( to, length ) - call check( abs( last - first ) == list%len(), "compare_list: length mis-match& + call check( abs( last - first ) == max( 0, work_to - work_from + 1 ), "compare_list: length mis-match& & call_number " // to_string( call_number ) ) j = merge(-1, 1, last < first) - do i = 1, list%len() - call check( list%get( fidx(i) ) == to_string( first + ( ( i - 1 ) * j ) ), & + do i = work_from, work_to + call check( list%get( fidx(i) ) == to_string( first + ( ( i - work_from ) * j ) ), & & "compare_list: call_number " // to_string( call_number ) & & // " fidx( " // to_string( i ) // " )") - call check( list%get( bidx(i) ) == to_string( last - ( i * j ) ), & + + k = length - ( work_to - ( i - work_from ) ) + 1 + call check( list%get( bidx(k) ) == & + & to_string( last - ( ( i - work_from + 1 ) * j ) ), & & "compare_list: call_number " // to_string( call_number ) & - & // " bidx( " // to_string( i ) // " )") + & // " bidx( " // to_string( k ) // " )") end do end subroutine compare_list @@ -385,6 +444,7 @@ program tester call test_insert_at_string_3 call test_insert_at_array call test_insert_at_list + call test_insert_at_same_list call test_constructor end program tester From a9a62881e13da791f54ce96e569022123018ac1f Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 17 Oct 2021 16:19:35 +0530 Subject: [PATCH 4/7] added length check --- src/tests/stringlist/test_insert_at.f90 | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/tests/stringlist/test_insert_at.f90 b/src/tests/stringlist/test_insert_at.f90 index 6c150826b..c6ef4b739 100644 --- a/src/tests/stringlist/test_insert_at.f90 +++ b/src/tests/stringlist/test_insert_at.f90 @@ -1,7 +1,7 @@ ! SPDX-Identifier: MIT module test_insert_at use stdlib_error, only: check - use stdlib_string_type, only: string_type, operator(//), operator(==) + use stdlib_string_type, only: string_type, operator(//), operator(==), char use stdlib_stringlist_type, only: stringlist_type, fidx, bidx, list_head, list_tail, operator(==) use stdlib_strings, only: to_string use stdlib_optval, only: optval @@ -355,29 +355,29 @@ end subroutine test_constructor subroutine test_insert_at_same_list type(stringlist_type) :: work_list type(stringlist_type) :: temp_list - integer :: i, j + integer :: i integer, parameter :: first = -100 integer, parameter :: last = 100 - integer, parameter :: stride = 4 write (*,*) "test_insert_at_same_list: Starting work_list!" call work_list%insert_at( list_head, work_list ) call work_list%insert_at( list_tail, work_list ) - do j = -10, 10 - call work_list%insert_at( fidx(j), work_list ) - call work_list%insert_at( bidx(j), work_list ) + do i = -10, 10 + call work_list%insert_at( fidx(i), work_list ) + call work_list%insert_at( bidx(i), work_list ) end do call compare_list( work_list, 0, 0, 13 ) + call check( work_list%len() == 0, "test_insert_at_same_list: empty list insertion") - do j = first, last - call work_list%insert_at( list_tail, string_type( to_string(j) ) ) + do i = first, last + call work_list%insert_at( list_tail, string_type( to_string(i) ) ) end do - temp_list = work_list + call work_list%insert_at( list_head, work_list ) call compare_list( work_list, first, last + 1, 14, to=last - first + 1 ) call compare_list( work_list, first, last + 1, 15, from=last - first + 2 ) @@ -390,13 +390,15 @@ subroutine test_insert_at_same_list work_list = temp_list call compare_list( work_list, first, last + 1, 18 ) - do j = 1, last - first + 2 + write (*,*) "test_insert_at_same_list: Starting temp_list!" + + do i = 1, last - first + 2 temp_list = work_list - call temp_list%insert_at( fidx(j), temp_list ) + call temp_list%insert_at( fidx(i), temp_list ) - call compare_list( temp_list, first, first + j - 1, 19, to=j - 1) - call compare_list( temp_list, first, last + 1, 20, from=j, to=j + last - first) - call compare_list( temp_list, first + j - 1, last + 1, 21, from=j + last - first + 1) + call compare_list( temp_list, first, first + i - 1, 19, to=i - 1 ) + call compare_list( temp_list, first, last + 1, 20, from=i, to=i + last - first ) + call compare_list( temp_list, first + i - 1, last + 1, 21, from=i + last - first + 1 ) end do @@ -421,13 +423,13 @@ subroutine compare_list(list, first, last, call_number, from, to) do i = work_from, work_to call check( list%get( fidx(i) ) == to_string( first + ( ( i - work_from ) * j ) ), & & "compare_list: call_number " // to_string( call_number ) & - & // " fidx( " // to_string( i ) // " )") + & // " fidx( " // to_string( i ) // " )" ) k = length - ( work_to - ( i - work_from ) ) + 1 call check( list%get( bidx(k) ) == & & to_string( last - ( ( i - work_from + 1 ) * j ) ), & & "compare_list: call_number " // to_string( call_number ) & - & // " bidx( " // to_string( k ) // " )") + & // " bidx( " // to_string( k ) // " )" ) end do end subroutine compare_list From 0bd66e1b939c87e50e8d046bfb5ee8ac42ac9ca7 Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 21 Nov 2021 21:44:43 +0530 Subject: [PATCH 5/7] a temp commit to test --- src/tests/stringlist/test_insert_at.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/stringlist/test_insert_at.f90 b/src/tests/stringlist/test_insert_at.f90 index c6ef4b739..e5838664c 100644 --- a/src/tests/stringlist/test_insert_at.f90 +++ b/src/tests/stringlist/test_insert_at.f90 @@ -1,7 +1,7 @@ ! SPDX-Identifier: MIT module test_insert_at use stdlib_error, only: check - use stdlib_string_type, only: string_type, operator(//), operator(==), char + use stdlib_string_type, only: string_type, operator(//), operator(==), char, operator(/=) use stdlib_stringlist_type, only: stringlist_type, fidx, bidx, list_head, list_tail, operator(==) use stdlib_strings, only: to_string use stdlib_optval, only: optval @@ -375,6 +375,7 @@ subroutine test_insert_at_same_list do i = first, last call work_list%insert_at( list_tail, string_type( to_string(i) ) ) + call check(string_type( to_string(i) ) /= "", "There is something wrong with this") end do temp_list = work_list From d946a354d104c1f246b7484a7cdc90afa107a50d Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 21 Nov 2021 22:00:43 +0530 Subject: [PATCH 6/7] again a temp commit --- src/tests/stringlist/test_insert_at.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stringlist/test_insert_at.f90 b/src/tests/stringlist/test_insert_at.f90 index e5838664c..aa1f01c13 100644 --- a/src/tests/stringlist/test_insert_at.f90 +++ b/src/tests/stringlist/test_insert_at.f90 @@ -380,7 +380,7 @@ subroutine test_insert_at_same_list temp_list = work_list call work_list%insert_at( list_head, work_list ) - call compare_list( work_list, first, last + 1, 14, to=last - first + 1 ) + ! call compare_list( work_list, first, last + 1, 14, to=last - first + 1 ) call compare_list( work_list, first, last + 1, 15, from=last - first + 2 ) work_list = temp_list From bb30a55a53b3728232727a3afdce168900b0be66 Mon Sep 17 00:00:00 2001 From: Aman-Godara Date: Sun, 21 Nov 2021 22:46:42 +0530 Subject: [PATCH 7/7] another temp commit --- src/stdlib_stringlist_type.f90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stdlib_stringlist_type.f90 b/src/stdlib_stringlist_type.f90 index c476be548..2ecddf0cb 100644 --- a/src/stdlib_stringlist_type.f90 +++ b/src/stdlib_stringlist_type.f90 @@ -643,7 +643,7 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist ) integer :: i integer :: work_idxn, inew - integer :: pre_length, post_length + integer :: pre_length, post_length, temp pre_length = slist%len() if (pre_length > 0) then @@ -653,12 +653,14 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist ) post_length = slist%len() inew = work_idxn - do i = 1, min( work_idxn - 1, pre_length ) + temp = min( work_idxn - 1, pre_length ) + do i = 1, temp list%stringarray(inew) = slist%stringarray(i) inew = inew + 1 end do - do i = work_idxn + post_length - pre_length, post_length + temp = work_idxn + post_length - pre_length + do i = temp, post_length list%stringarray(inew) = slist%stringarray(i) inew = inew + 1 end do