Skip to content

Commit a9a6288

Browse files
committed
added length check
1 parent 875def4 commit a9a6288

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/tests/stringlist/test_insert_at.f90

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! SPDX-Identifier: MIT
22
module test_insert_at
33
use stdlib_error, only: check
4-
use stdlib_string_type, only: string_type, operator(//), operator(==)
4+
use stdlib_string_type, only: string_type, operator(//), operator(==), char
55
use stdlib_stringlist_type, only: stringlist_type, fidx, bidx, list_head, list_tail, operator(==)
66
use stdlib_strings, only: to_string
77
use stdlib_optval, only: optval
@@ -355,29 +355,29 @@ end subroutine test_constructor
355355
subroutine test_insert_at_same_list
356356
type(stringlist_type) :: work_list
357357
type(stringlist_type) :: temp_list
358-
integer :: i, j
358+
integer :: i
359359
integer, parameter :: first = -100
360360
integer, parameter :: last = 100
361-
integer, parameter :: stride = 4
362361

363362
write (*,*) "test_insert_at_same_list: Starting work_list!"
364363

365364
call work_list%insert_at( list_head, work_list )
366365
call work_list%insert_at( list_tail, work_list )
367366

368-
do j = -10, 10
369-
call work_list%insert_at( fidx(j), work_list )
370-
call work_list%insert_at( bidx(j), work_list )
367+
do i = -10, 10
368+
call work_list%insert_at( fidx(i), work_list )
369+
call work_list%insert_at( bidx(i), work_list )
371370

372371
end do
373372

374373
call compare_list( work_list, 0, 0, 13 )
374+
call check( work_list%len() == 0, "test_insert_at_same_list: empty list insertion")
375375

376-
do j = first, last
377-
call work_list%insert_at( list_tail, string_type( to_string(j) ) )
376+
do i = first, last
377+
call work_list%insert_at( list_tail, string_type( to_string(i) ) )
378378
end do
379-
380379
temp_list = work_list
380+
381381
call work_list%insert_at( list_head, work_list )
382382
call compare_list( work_list, first, last + 1, 14, to=last - first + 1 )
383383
call compare_list( work_list, first, last + 1, 15, from=last - first + 2 )
@@ -390,13 +390,15 @@ subroutine test_insert_at_same_list
390390
work_list = temp_list
391391
call compare_list( work_list, first, last + 1, 18 )
392392

393-
do j = 1, last - first + 2
393+
write (*,*) "test_insert_at_same_list: Starting temp_list!"
394+
395+
do i = 1, last - first + 2
394396
temp_list = work_list
395-
call temp_list%insert_at( fidx(j), temp_list )
397+
call temp_list%insert_at( fidx(i), temp_list )
396398

397-
call compare_list( temp_list, first, first + j - 1, 19, to=j - 1)
398-
call compare_list( temp_list, first, last + 1, 20, from=j, to=j + last - first)
399-
call compare_list( temp_list, first + j - 1, last + 1, 21, from=j + last - first + 1)
399+
call compare_list( temp_list, first, first + i - 1, 19, to=i - 1 )
400+
call compare_list( temp_list, first, last + 1, 20, from=i, to=i + last - first )
401+
call compare_list( temp_list, first + i - 1, last + 1, 21, from=i + last - first + 1 )
400402

401403
end do
402404

@@ -421,13 +423,13 @@ subroutine compare_list(list, first, last, call_number, from, to)
421423
do i = work_from, work_to
422424
call check( list%get( fidx(i) ) == to_string( first + ( ( i - work_from ) * j ) ), &
423425
& "compare_list: call_number " // to_string( call_number ) &
424-
& // " fidx( " // to_string( i ) // " )")
426+
& // " fidx( " // to_string( i ) // " )" )
425427

426428
k = length - ( work_to - ( i - work_from ) ) + 1
427429
call check( list%get( bidx(k) ) == &
428430
& to_string( last - ( ( i - work_from + 1 ) * j ) ), &
429431
& "compare_list: call_number " // to_string( call_number ) &
430-
& // " bidx( " // to_string( k ) // " )")
432+
& // " bidx( " // to_string( k ) // " )" )
431433
end do
432434

433435
end subroutine compare_list

0 commit comments

Comments
 (0)