Skip to content

Commit 9b63241

Browse files
committed
Updated stream removal tests and deleted unused stream test variables.
Created a test that tests removing a stream at the beginning, middle, and end of a mpas_stream_list object.
1 parent 04ce2d2 commit 9b63241

File tree

1 file changed

+79
-40
lines changed

1 file changed

+79
-40
lines changed

src/core_test/mpas_test_core_stream_list.F

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,95 @@ subroutine mpas_test_query_exact_match(err)
138138
end subroutine mpas_test_query_exact_match
139139
140140
!**************************************************************************************
141-
! Subroutine mpas_test_remove_head
141+
! Subroutine mpas_test_remove_existing_streams
142142
!
143-
!> \brief Test removing the head stream from the list and verify removal.
143+
!> \brief Test removing streams from the beginning, middle, and end of a list.
144144
!>
145-
!> \details This subroutine tests the removal of the head stream from an MPAS
146-
!> stream list. It ensures that the correct stream is removed and that
147-
!> the list's state is properly updated after removal.
145+
!> \details This subroutine verifies that removing streams from different positions
146+
!> in an MPAS stream list works as expected. It inserts three streams into
147+
!> the list, then removes one from the middle, one from the end, and one
148+
!> from the beginning, checking that the correct stream is removed in each
149+
!> case and that the operation returns a success code.
148150
!>
149151
!> \param err The error code that indicates the result of the test.
150-
!
151-
!--------------------------------------------------------------------------------------
152-
subroutine mpas_test_remove_head(err)
152+
!>
153+
!**************************************************************************************
154+
subroutine mpas_test_remove_existing_streams(err)
153155
integer, intent(out) :: err
154-
type(MPAS_stream_list_type), pointer :: list, stream, removed
156+
type(MPAS_stream_list_type), pointer :: list, s1, s2, s3, &
157+
removed1, removed2, removed3
158+
integer :: ierr
155159
156160
err = 0
157161
158-
call MPAS_stream_list_create(list)
159-
allocate(stream)
160-
stream%name = 'stream1'
161-
call MPAS_stream_list_insert(list, stream)
162+
allocate(s1)
163+
s1%name = 'stream1'
164+
allocate(s2)
165+
s2%name = 'stream2'
166+
allocate(s3)
167+
s3%name = 'stream3'
162168
163-
call MPAS_stream_list_remove(list, 'stream1', removed)
169+
call MPAS_stream_list_create(list, ierr=ierr)
170+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
171+
err = err + 1
172+
end if
164173
165-
if (.not. associated(removed)) then
174+
call MPAS_stream_list_insert(list, s1, ierr=ierr)
175+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
166176
err = err + 1
167177
end if
168178
169-
if (trim(removed%name) /= 'stream1') then
179+
call MPAS_stream_list_insert(list, s2, ierr=ierr)
180+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
170181
err = err + 1
171182
end if
172183
173-
if (list%nItems /= 0) then
184+
call MPAS_stream_list_insert(list, s3, ierr=ierr)
185+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
186+
err = err + 1
187+
end if
188+
189+
! Remove from the middle
190+
call MPAS_stream_list_remove(list, 'stream2', removed2, ierr=ierr)
191+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
192+
err = err + 1
193+
end if
194+
if (.not. associated(removed2)) then
195+
err = err + 1
196+
end if
197+
if (trim(removed2%name) /= 'stream2') then
198+
err = err + 1
199+
end if
200+
201+
! Remove from the end
202+
call MPAS_stream_list_remove(list, 'stream3', removed3, ierr=ierr)
203+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
204+
err = err + 1
205+
end if
206+
if (.not. associated(removed3)) then
207+
err = err + 1
208+
end if
209+
if (trim(removed3%name) /= 'stream3') then
210+
err = err + 1
211+
end if
212+
213+
! Remove from the beginning
214+
call MPAS_stream_list_remove(list, 'stream1', removed1, ierr=ierr)
215+
if (ierr /= MPAS_STREAM_LIST_NOERR) then
216+
err = err + 1
217+
end if
218+
if (.not. associated(removed1)) then
219+
err = err + 1
220+
end if
221+
if (trim(removed1%name) /= 'stream1') then
174222
err = err + 1
175223
end if
176224
177225
call MPAS_stream_list_destroy(list)
178-
deallocate(removed)
179-
end subroutine mpas_test_remove_head
226+
deallocate(removed1)
227+
deallocate(removed2)
228+
deallocate(removed3)
229+
end subroutine mpas_test_remove_existing_streams
180230
181231
!**************************************************************************************
182232
! Subroutine mpas_test_insert_duplicate_at_begin_and_end
@@ -193,7 +243,7 @@ end subroutine mpas_test_remove_head
193243
subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
194244
integer, intent(out) :: err
195245
type(MPAS_stream_list_type), pointer :: list
196-
type(MPAS_stream_list_type), pointer :: s1, s2, s1_dup
246+
type(MPAS_stream_list_type), pointer :: s1, s2
197247
integer :: ierr
198248
199249
err = 0
@@ -203,8 +253,6 @@ subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
203253
s1%name = 'stream1'
204254
allocate(s2)
205255
s2%name = 'stream2'
206-
allocate(s1_dup)
207-
s1_dup%name = 'stream1'
208256
209257
call MPAS_stream_list_insert(list, s1, ierr)
210258
if (ierr /= MPAS_STREAM_LIST_NOERR) then
@@ -216,13 +264,12 @@ subroutine mpas_test_insert_duplicate_at_begin_and_end(err)
216264
err = err + 1
217265
end if
218266
219-
call MPAS_stream_list_insert(list, s1_dup, ierr)
267+
call MPAS_stream_list_insert(list, s1, ierr)
220268
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
221269
err = err + 1
222270
end if
223271
224272
call MPAS_stream_list_destroy(list)
225-
deallocate(s1_dup)
226273
end subroutine mpas_test_insert_duplicate_at_begin_and_end
227274
228275
!**************************************************************************************
@@ -397,7 +444,7 @@ end subroutine mpas_test_query_partial_match
397444
subroutine mpas_test_insert_duplicate_at_begin(err)
398445
integer, intent(out) :: err
399446
type(MPAS_stream_list_type), pointer :: list
400-
type(MPAS_stream_list_type), pointer :: s1, s1_dup
447+
type(MPAS_stream_list_type), pointer :: s1
401448
integer :: ierr
402449

403450
err = 0
@@ -406,21 +453,17 @@ subroutine mpas_test_insert_duplicate_at_begin(err)
406453
allocate(s1)
407454
s1%name = 'stream1'
408455

409-
allocate(s1_dup)
410-
s1_dup%name = 'stream1'
411-
412456
call MPAS_stream_list_insert(list, s1, ierr)
413457
if (ierr /= MPAS_STREAM_LIST_NOERR) then
414458
err = err + 1
415459
end if
416460

417-
call MPAS_stream_list_insert(list, s1_dup, ierr)
461+
call MPAS_stream_list_insert(list, s1, ierr)
418462
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
419463
err = err + 1
420464
end if
421465

422466
call MPAS_stream_list_destroy(list)
423-
deallocate(s1_dup)
424467
end subroutine mpas_test_insert_duplicate_at_begin
425468

426469
!**************************************************************************************
@@ -438,7 +481,7 @@ end subroutine mpas_test_insert_duplicate_at_begin
438481
subroutine mpas_test_insert_duplicate_at_end(err)
439482
integer, intent(out) :: err
440483
type(MPAS_stream_list_type), pointer :: list
441-
type(MPAS_stream_list_type), pointer :: s1, s2, s2_dup
484+
type(MPAS_stream_list_type), pointer :: s1, s2
442485
integer :: ierr
443486

444487
err = 0
@@ -450,9 +493,6 @@ subroutine mpas_test_insert_duplicate_at_end(err)
450493
allocate(s2)
451494
s2%name = 'stream2'
452495

453-
allocate(s2_dup)
454-
s2_dup%name = 'stream2'
455-
456496
call MPAS_stream_list_insert(list, s1, ierr)
457497
if (ierr /= MPAS_STREAM_LIST_NOERR) then
458498
err = err + 1
@@ -463,13 +503,12 @@ subroutine mpas_test_insert_duplicate_at_end(err)
463503
err = err + 1
464504
end if
465505

466-
call MPAS_stream_list_insert(list, s2_dup, ierr)
506+
call MPAS_stream_list_insert(list, s2, ierr)
467507
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
468508
err = err + 1
469509
end if
470510

471511
call MPAS_stream_list_destroy(list)
472-
deallocate(s2_dup)
473512
end subroutine mpas_test_insert_duplicate_at_end
474513

475514

@@ -522,13 +561,13 @@ subroutine mpas_test_stream_list(err)
522561
call mpas_log_write(' mpas_test_query_exact_match: FAILURE')
523562
end if
524563

525-
! Test removing the head stream from the list and verify removal.
526-
call mpas_test_remove_head(test_err)
564+
! Test removing streams at beginning, middle, and end of a list.
565+
call mpas_test_remove_existing_streams(test_err)
527566
if (test_err == 0) then
528-
call mpas_log_write(' mpas_test_remove_head: SUCCESS')
567+
call mpas_log_write(' mpas_test_remove_existing_streams: SUCCESS')
529568
else
530569
err = err + test_err
531-
call mpas_log_write(' mpas_test_remove_head: FAILURE')
570+
call mpas_log_write(' mpas_test_remove_existing_streams: FAILURE')
532571
end if
533572

534573
! Test inserting a duplicate stream at both the beginning and the end of the list.

0 commit comments

Comments
 (0)