Skip to content

Commit 3ddfa93

Browse files
committed
added 3rd test case for insert_at
1 parent 42487ea commit 3ddfa93

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/tests/stringlist/test_insert_at.f90

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,77 @@ subroutine test_insert_at_2
150150

151151
end subroutine test_insert_at_2
152152

153+
subroutine test_insert_at_3
154+
type(stringlist_type) :: work_list
155+
integer :: i, current_length
156+
character(len=:), allocatable :: string
157+
integer, parameter :: first = 2
158+
integer, parameter :: last = 20
159+
160+
write (*,*) "test_insert_at_3: Starting test case 1!"
161+
162+
current_length = 0
163+
do i = first, last, 2
164+
string = to_string( i )
165+
call work_list%insert_at( bidx(i), string )
166+
current_length = current_length + 1
167+
168+
call check( work_list%get( bidx(current_length) ) == string, "test_insert_at_3:&
169+
& get bidx(current_length) " // string )
170+
call check( work_list%get( bidx(1) ) == to_string(first), "test_insert_at_3:&
171+
& get bidx(1) " // string )
172+
call check( work_list%get( list_tail ) == to_string(first), "test_insert_at_3:&
173+
& get list_tail " // string )
174+
call check( work_list%get( fidx(1) ) == string, "test_insert_at_3:&
175+
& get fidx(1) " // string )
176+
call check( work_list%get( fidx(current_length) ) == to_string(first), "test_insert_at_3: get&
177+
& fidx(current_length) " // string )
178+
call check( work_list%get( list_head ) == string, "test_insert_at_3: get&
179+
& list_head " // string )
180+
181+
call check( work_list%to_current_idxn( list_head ) == 1, "test_insert_at_3:&
182+
& to_current_idxn( list_head ) " // to_string( current_length ) )
183+
call check( work_list%to_current_idxn( list_tail ) == current_length, "test_insert_at_3:&
184+
& to_current_idxn( list_tail ) " // to_string( current_length ) )
185+
call check( work_list%len() == current_length, "test_insert_at_3: length check "&
186+
& // to_string( current_length ) )
187+
188+
end do
189+
190+
write (*,*) "test_insert_at_3: Starting test case 2!"
191+
192+
do i = first - 1, last - 1, 2
193+
string = to_string( i )
194+
call work_list%insert_at( bidx(i), string )
195+
current_length = current_length + 1
196+
197+
call check( work_list%get( bidx(i) ) == string, "test_insert_at_3:&
198+
& get bidx(current_length) " // string )
199+
call check( work_list%get( bidx(1) ) == to_string(first - 1), "test_insert_at_3:&
200+
& get bidx(1) " // string )
201+
call check( work_list%get( list_tail ) == to_string(first - 1), "test_insert_at_3:&
202+
& get list_tail " // string )
203+
call check( work_list%get( fidx(1) ) == to_string(last), "test_insert_at_3:&
204+
& get fidx(1) " // string )
205+
call check( work_list%get( fidx(current_length) ) == to_string(first - 1), "test_insert_at_3: get&
206+
& fidx(current_length) " // string )
207+
call check( work_list%get( list_head ) == to_string(last), "test_insert_at_3: get&
208+
& list_head " // string )
209+
210+
call check( work_list%to_current_idxn( list_head ) == 1, "test_insert_at_3:&
211+
& to_current_idxn( list_head ) " // to_string( current_length ) )
212+
call check( work_list%to_current_idxn( list_tail ) == current_length, "test_insert_at_3:&
213+
& to_current_idxn( list_tail ) " // to_string( current_length ) )
214+
call check( work_list%len() == current_length, "test_insert_at_3: length check "&
215+
& // to_string( current_length ) )
216+
217+
end do
218+
219+
! compare work_list with [20, 19, ..., ..., 2, 1]
220+
call compare_list( work_list, last, first - 2, 4 )
221+
222+
end subroutine test_insert_at_3
223+
153224
! compares input stringlist 'list' with an array of consecutive integers
154225
! array is 'first' inclusive and 'last' exclusive
155226
subroutine compare_list(list, first, last, call_number)
@@ -181,5 +252,6 @@ program tester
181252

182253
call test_insert_at_1
183254
call test_insert_at_2
255+
call test_insert_at_3
184256

185257
end program tester

0 commit comments

Comments
 (0)