Skip to content

Commit 573dbfa

Browse files
committed
avoid a single logical treating many tests
1 parent 8a803e9 commit 573dbfa

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

src/tests/selection/test_selection.fypp

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ contains
5454
kth_smallest, random_vals(Nr), one = 1
5555
${inttype}$ :: i, p, up_rank, down_rank, mid_rank
5656
real(dp) :: random_doubles(Nr) ! Deliberately double precision for all cases
57-
logical :: test1, test2, test3, any_failed
57+
logical :: test1, test2, test3
5858
integer, parameter :: ip = ${intkind}$
5959

6060
! x contains the numbers 1**2, 2**2, .... 10**2, with mixed-up order
@@ -142,8 +142,6 @@ contains
142142
!
143143
! Test using random data
144144
!
145-
any_failed=.FALSE.
146-
147145
! Search for the p-th smallest rank, for all these p
148146
! (avoid end-points to enable constrained search tests)
149147
do p = 3, Nr-2
@@ -161,8 +159,8 @@ contains
161159
test2 = all(random_vals(1:(p-1)) <= random_vals(p))
162160
test3 = all(random_vals(p) <= &
163161
random_vals((p+1):size(random_vals, kind=ip)))
164-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
165-
any_failed = .TRUE.
162+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data regular select")
163+
if(allocated(error)) return
166164

167165
! Constrained search above 'p', providing 'left'
168166
up_rank = p + (Nr-p)/2_ip ! Deliberate integer division
@@ -172,8 +170,8 @@ contains
172170
test2 = all(random_vals(1:(up_rank-1)) <= random_vals(up_rank))
173171
test3 = all(random_vals(up_rank) <= &
174172
random_vals((up_rank+1):size(random_vals, kind=ip)))
175-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
176-
any_failed = .TRUE.
173+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data left-constrained select")
174+
if(allocated(error)) return
177175

178176
! Constrained search below p, providing 'right'
179177
down_rank = p - (p/2_ip)
@@ -184,8 +182,8 @@ contains
184182
random_vals(down_rank))
185183
test3 = all(random_vals(down_rank) <= &
186184
random_vals((down_rank+1):size(random_vals, kind=ip)))
187-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
188-
any_failed = .TRUE.
185+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data right-constrained select")
186+
if(allocated(error)) return
189187

190188
! Constrained search between up-ind and down-ind, proving left
191189
! and right. Make 'mid_rank' either above or below p
@@ -198,16 +196,12 @@ contains
198196
random_vals(mid_rank))
199197
test3 = all(random_vals(mid_rank) <= &
200198
random_vals((mid_rank+1):size(random_vals, kind=ip)))
201-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
202-
any_failed = .TRUE.
199+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data left-right-constrained select")
200+
if(allocated(error)) return
203201

204202
end do
205203
end do
206204

207-
call check(error, (.not. any_failed), " ${name}$: random number test failed ")
208-
if(allocated(error)) return
209-
210-
211205
end subroutine
212206
#:endfor
213207
#:endfor
@@ -229,7 +223,7 @@ contains
229223
indx_len1(1), indx_len2(2), indx_r(Nr)
230224
real(dp) :: random_doubles(Nr) ! Deliberately double precision for all cases
231225
integer(ip) :: i, j, p, up_rank, down_rank, mid_rank, kth_smallest
232-
logical :: test1, test2, test3, any_failed
226+
logical :: test1, test2, test3
233227

234228
! Make x contain 1**2, 2**2, .... 10**2, but mix up the order
235229
x = (/( i**2, i=1, size(x, kind=ip) )/)
@@ -334,8 +328,6 @@ contains
334328
!
335329
! Test using random data
336330
!
337-
any_failed=.FALSE.
338-
339331
! Search for the p-th smallest, for all these p (avoid end-points to
340332
! enable additional tests using "left", "right" arguments)
341333
do p = 3, Nr-2
@@ -357,8 +349,8 @@ contains
357349
random_vals(indx_r(p)))
358350
test3 = all(random_vals(indx_r(p)) <= &
359351
random_vals(indx_r((p+1):size(random_vals, kind=ip))))
360-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
361-
any_failed = .TRUE.
352+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data regular arg_select")
353+
if(allocated(error)) return
362354

363355
! Constrained search for a rank above 'p', providing 'left'
364356
up_rank = p + (Nr-p)/2_ip ! Deliberate integer division
@@ -371,8 +363,9 @@ contains
371363
random_vals(indx_r(up_rank)))
372364
test3 = all(random_vals(indx_r(up_rank)) <= &
373365
random_vals(indx_r((up_rank+1):size(random_vals, kind=ip))))
374-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
375-
any_failed = .TRUE.
366+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data left-constrained arg_select")
367+
if(allocated(error)) return
368+
376369

377370
! Constrained search for a rank below p, providing 'right'
378371
down_rank = p - (p/2_ip)
@@ -385,8 +378,8 @@ contains
385378
random_vals(indx_r(down_rank)))
386379
test3 = all(random_vals(indx_r(down_rank)) <= &
387380
random_vals(indx_r((down_rank+1):size(random_vals, kind=ip))))
388-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
389-
any_failed = .TRUE.
381+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data right-constrained arg_select")
382+
if(allocated(error)) return
390383

391384
! Constrained search for a rank between up-ind and down-ind,
392385
! proving left and right. 'mid_rank' is either above or below p
@@ -400,15 +393,12 @@ contains
400393
random_vals(indx_r(mid_rank)))
401394
test3 = all(random_vals(indx_r(mid_rank)) <= &
402395
random_vals(indx_r((mid_rank+1):size(random_vals, kind=ip))))
403-
if( (.not. test1) .or. (.not. test2) .or. (.not. test3) ) &
404-
any_failed = .TRUE.
396+
call check(error, (test1 .and. test2 .and. test3), "${name}$: random data left-right-constrained arg_select")
397+
if(allocated(error)) return
405398

406399
end do
407400
end do
408401

409-
call check(error, (.not. any_failed), " ${name}$: random number test failed ")
410-
if(allocated(error)) return
411-
412402
end subroutine
413403
#:endfor
414404
#:endfor

0 commit comments

Comments
 (0)