Skip to content

Commit 2a5f9d6

Browse files
author
Andy Stokely
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 3845692 commit 2a5f9d6

File tree

1 file changed

+79
-42
lines changed

1 file changed

+79
-42
lines changed

src/core_test/mpas_test_core_stream_list.F

Lines changed: 79 additions & 42 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-
!
152+
!>
151153
!--------------------------------------------------------------------------------------
152-
subroutine mpas_test_remove_head(err)
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
!**************************************************************************************
@@ -239,12 +286,10 @@ end subroutine mpas_test_insert_duplicate_at_begin_and_end
239286
!--------------------------------------------------------------------------------------
240287
subroutine mpas_test_remove_from_empty_list(err)
241288
integer, intent(out) :: err
242-
type(MPAS_stream_list_type), pointer :: list, s1, removed
289+
type(MPAS_stream_list_type), pointer :: list, removed
243290
integer :: ierr
244291
245292
err = 0
246-
allocate(s1)
247-
s1%name = 'stream1'
248293
249294
call MPAS_stream_list_create(list)
250295
@@ -397,7 +442,7 @@ end subroutine mpas_test_query_partial_match
397442
subroutine mpas_test_insert_duplicate_at_begin(err)
398443
integer, intent(out) :: err
399444
type(MPAS_stream_list_type), pointer :: list
400-
type(MPAS_stream_list_type), pointer :: s1, s1_dup
445+
type(MPAS_stream_list_type), pointer :: s1
401446
integer :: ierr
402447

403448
err = 0
@@ -406,21 +451,17 @@ subroutine mpas_test_insert_duplicate_at_begin(err)
406451
allocate(s1)
407452
s1%name = 'stream1'
408453

409-
allocate(s1_dup)
410-
s1_dup%name = 'stream1'
411-
412454
call MPAS_stream_list_insert(list, s1, ierr)
413455
if (ierr /= MPAS_STREAM_LIST_NOERR) then
414456
err = err + 1
415457
end if
416458

417-
call MPAS_stream_list_insert(list, s1_dup, ierr)
459+
call MPAS_stream_list_insert(list, s1, ierr)
418460
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
419461
err = err + 1
420462
end if
421463

422464
call MPAS_stream_list_destroy(list)
423-
deallocate(s1_dup)
424465
end subroutine mpas_test_insert_duplicate_at_begin
425466

426467
!**************************************************************************************
@@ -438,7 +479,7 @@ end subroutine mpas_test_insert_duplicate_at_begin
438479
subroutine mpas_test_insert_duplicate_at_end(err)
439480
integer, intent(out) :: err
440481
type(MPAS_stream_list_type), pointer :: list
441-
type(MPAS_stream_list_type), pointer :: s1, s2, s2_dup
482+
type(MPAS_stream_list_type), pointer :: s1, s2
442483
integer :: ierr
443484

444485
err = 0
@@ -450,9 +491,6 @@ subroutine mpas_test_insert_duplicate_at_end(err)
450491
allocate(s2)
451492
s2%name = 'stream2'
452493

453-
allocate(s2_dup)
454-
s2_dup%name = 'stream2'
455-
456494
call MPAS_stream_list_insert(list, s1, ierr)
457495
if (ierr /= MPAS_STREAM_LIST_NOERR) then
458496
err = err + 1
@@ -463,13 +501,12 @@ subroutine mpas_test_insert_duplicate_at_end(err)
463501
err = err + 1
464502
end if
465503

466-
call MPAS_stream_list_insert(list, s2_dup, ierr)
504+
call MPAS_stream_list_insert(list, s2, ierr)
467505
if (ierr /= MPAS_STREAM_LIST_DUPLICATE) then
468506
err = err + 1
469507
end if
470508

471509
call MPAS_stream_list_destroy(list)
472-
deallocate(s2_dup)
473510
end subroutine mpas_test_insert_duplicate_at_end
474511

475512

@@ -522,13 +559,13 @@ subroutine mpas_test_stream_list(err)
522559
call mpas_log_write(' mpas_test_query_exact_match: FAILURE')
523560
end if
524561

525-
! Test removing the head stream from the list and verify removal.
526-
call mpas_test_remove_head(test_err)
562+
! Test removing streams at beginning, middle, and end of a list.
563+
call mpas_test_remove_existing_streams(test_err)
527564
if (test_err == 0) then
528-
call mpas_log_write(' mpas_test_remove_head: SUCCESS')
565+
call mpas_log_write(' mpas_test_remove_existing_streams: SUCCESS')
529566
else
530567
err = err + test_err
531-
call mpas_log_write(' mpas_test_remove_head: FAILURE')
568+
call mpas_log_write(' mpas_test_remove_existing_streams: FAILURE')
532569
end if
533570

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

0 commit comments

Comments
 (0)