@@ -8,9 +8,9 @@ module prif_co_max_test_m
8
8
use iso_c_binding, only: c_size_t, c_ptr, c_intmax_t, c_null_funptr
9
9
use prif, only : prif_co_max, prif_num_images, prif_this_image_no_coarray, prif_num_images
10
10
use prif_test_m, only : prif_test_t, test_description_substring
11
- use julienne_m, only : test_result_t, test_description_t
11
+ use julienne_m, only : test_result_t, test_description_t, test_diagnosis_t, string_t, operator (.csv.)
12
12
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
13
- use julienne_m, only : test_function_i
13
+ use julienne_m, only : diagnosis_function_i
14
14
#endif
15
15
implicit none
16
16
@@ -47,7 +47,7 @@ function results() result(test_results)
47
47
,test_description_t(" default-character variables with no optional arguments" , reverse_alphabetize_default_characters) &
48
48
]
49
49
#else
50
- procedure (test_function_i ), pointer :: &
50
+ procedure (diagnosis_function_i ), pointer :: &
51
51
max_default_integer_scalars_ptr = > max_default_integer_scalars &
52
52
,max_c_int64_scalars_ptr = > max_c_int64_scalars &
53
53
,max_default_integer_1D_array_ptr = > max_default_integer_1D_array &
@@ -76,20 +76,24 @@ function results() result(test_results)
76
76
test_results = test_descriptions% run()
77
77
end function
78
78
79
- function max_default_integer_scalars () result(test_passes )
80
- logical test_passes
79
+ function max_default_integer_scalars () result(test_diagnosis )
80
+ type (test_diagnosis_t) test_diagnosis
81
81
integer i, status_, n
82
82
83
83
status_ = - 1
84
84
call prif_this_image_no_coarray(this_image= i)
85
85
call prif_co_max(i, stat= status_)
86
86
call prif_num_images(num_images= n)
87
- test_passes = i == n .and. status_ == 0
87
+ test_diagnosis = test_diagnosis_t( &
88
+ test_passed = (i== n) .and. (status_== 0 ) &
89
+ ,diagnostics_string = " expected i = " // string_t(i) // " , status_ = 0" &
90
+ // " ; actual i = " // string_t(n) // " , status_ = " // string_t(status_) &
91
+ )
88
92
end function
89
93
90
- function max_c_int64_scalars () result(test_passes )
94
+ function max_c_int64_scalars () result(test_diagnosis )
91
95
use iso_c_binding, only : c_int64_t
92
- logical test_passes
96
+ type (test_diagnosis_t) test_diagnosis
93
97
integer (c_int64_t) i
94
98
integer me, status_, n
95
99
@@ -98,11 +102,15 @@ function max_c_int64_scalars() result(test_passes)
98
102
i = me
99
103
call prif_co_max(i, stat= status_)
100
104
call prif_num_images(num_images= n)
101
- test_passes = i == int (n)
105
+ test_diagnosis = test_diagnosis_t( &
106
+ test_passed = (i == int (n,c_int64_t)) .and. (status_ == 0 ) &
107
+ ,diagnostics_string = " expected i = " // string_t(int (i)) // " , status = 0" &
108
+ // " ; actual i = " // string_t(n) // " , status = " // string_t(status_) &
109
+ )
102
110
end function
103
111
104
- function max_default_integer_1D_array () result(test_passes )
105
- logical test_passes
112
+ function max_default_integer_1D_array () result(test_diagnosis )
113
+ type (test_diagnosis_t) test_diagnosis
106
114
integer i, me, n
107
115
integer , allocatable :: array(:)
108
116
@@ -112,73 +120,102 @@ function max_default_integer_1D_array() result(test_passes)
112
120
array = sequence_
113
121
call prif_co_max(array)
114
122
associate(max_sequence = > n* [(i, i= 1 , n)])
115
- test_passes = all (max_sequence == array)
123
+ test_diagnosis = test_diagnosis_t( &
124
+ test_passed = all (max_sequence == array), &
125
+ diagnostics_string = " expected element values " // .csv. string_t(max_sequence) &
126
+ // " ; actual element values " // .csv. string_t(array) &
127
+ )
116
128
end associate
117
129
end associate
118
130
end function
119
131
120
- function max_default_integer_7D_array () result(test_passes)
121
- logical test_passes
122
- integer array(2 ,1 ,1 , 1 ,1 ,1 , 2 ), status_, me, n
132
+ function max_default_integer_7D_array () result(test_diagnosis)
133
+ type (test_diagnosis_t) test_diagnosis
134
+ integer , target :: array(2 ,1 ,1 , 1 ,1 ,1 , 2 )
135
+ integer , pointer :: array_1D_ptr(:)
136
+ integer status_, me, n
123
137
124
138
status_ = - 1
125
139
call prif_this_image_no_coarray(this_image= me)
126
140
array = 3 - me
127
141
call prif_co_max(array, stat= status_)
128
142
call prif_num_images(num_images= n)
129
- test_passes = all (array == 3 - 1 ) .and. status_ == 0
143
+ array_1D_ptr(1 :size (array)) = > array
144
+ test_diagnosis = test_diagnosis_t( &
145
+ test_passed = all (array == 3 - 1 ) .and. status_ == 0 &
146
+ ,diagnostics_string = " expected element values " // string_t(3 - 1 ) &
147
+ // " ; actual element values " // .csv. string_t(array_1D_ptr) &
148
+ )
130
149
end function
131
150
132
- function max_default_real_scalars () result(test_passes )
133
- logical test_passes
151
+ function max_default_real_scalars () result(test_diagnosis )
152
+ type (test_diagnosis_t) test_diagnosis
134
153
real scalar
135
- real , parameter :: pi = 3.141592654
154
+ real , parameter :: pi = 3.141592654 , tolerance = 1E-7 , expected = - pi
136
155
integer status_, me, n
137
156
138
157
status_ = - 1
139
158
call prif_this_image_no_coarray(this_image= me)
140
159
scalar = - pi* me
141
160
call prif_co_max(scalar, stat= status_)
142
161
call prif_num_images(num_images= n)
143
- test_passes = - dble (pi* 1 ) == dble (scalar) .and. status_ == 0
162
+ test_diagnosis = test_diagnosis_t( &
163
+ test_passed = (abs (scalar- expected) < tolerance) .and. (status_ == 0 ) &
164
+ ,diagnostics_string = " expected scalar " // string_t(expected) // " , status = 0" &
165
+ // " ; actual scalar " // string_t(scalar) // " , status = " // string_t(status_) &
166
+ )
144
167
end function
145
168
146
- function max_double_precision_2D_array () result(test_passes)
147
- logical test_passes
148
- double precision , allocatable :: array(:,:)
149
- double precision , parameter :: tent(* ,* ) = dble (reshape (- [0 ,1 ,2 ,3 ,2 ,1 ], [3 ,2 ]))
169
+ function max_double_precision_2D_array () result(test_diagnosis)
170
+ type (test_diagnosis_t) test_diagnosis
171
+ double precision , dimension (:,:), allocatable , target :: array, expected
172
+ double precision , dimension (:), pointer :: array_1D_ptr, expected_1D_ptr
173
+ double precision , parameter :: tent(* ,* ) = dble (reshape (- [0 ,1 ,2 ,3 ,2 ,1 ], [3 ,2 ])), tolerance = 1D-14
150
174
integer :: me, n
151
175
152
176
call prif_this_image_no_coarray(this_image= me)
153
177
array = tent* dble (me)
154
178
call prif_co_max(array)
155
179
call prif_num_images(num_images= n)
156
- test_passes = all (array== tent* dble (1 ))
180
+ expected = tent* dble (1 )
181
+ array_1D_ptr(1 :size (array)) = > array
182
+ expected_1D_ptr(1 :size (expected)) = > expected
183
+ test_diagnosis = test_diagnosis_t( &
184
+ test_passed = all (abs (array- expected) < tolerance) &
185
+ ,diagnostics_string = " expected element values " // .csv. string_t(expected_1D_ptr) &
186
+ // " ; actual element values " // .csv. string_t(array_1D_ptr) &
187
+ )
157
188
end function
158
189
159
- function max_elements_in_2D_string_arrays () result(test_passes )
160
- logical test_passes
190
+ function max_elements_in_2D_string_arrays () result(test_diagnosis )
191
+ type (test_diagnosis_t) test_diagnosis
161
192
character (len=* ), parameter :: script(* ,* ,* ) = reshape ( &
162
193
[ " To be " ," or not " & ! odd images get
163
194
, " to " ," be. " & ! this slice: script(:,:,1)
164
195
!- -------------------------
165
196
, " that " ," is " & ! even images get
166
197
, " the " ," question" ], & ! this slice: script(:,:,2)
167
198
[2 ,2 ,2 ])
168
- character (len= len (script)), dimension (size (script,1 ),size (script,2 )) :: slice
199
+ character (len= len (script)), dimension (size (script,1 ),size (script,2 )), target :: slice, expected
200
+ character (len= len (script)), dimension (:), pointer :: slice_1D_ptr, expected_1D_ptr
169
201
integer me, ni
170
202
171
203
call prif_this_image_no_coarray(this_image= me)
172
204
call prif_num_images(ni)
173
205
slice = script(:,:,mod (me-1 ,size (script,3 ))+ 1 )
174
206
call prif_co_max(slice)
175
- associate(expected = > maxval (script(:,:,1 :min (ni,size (script,3 ))), dim= 3 ))
176
- test_passes = all (expected == slice)
177
- end associate
207
+ expected = maxval (script(:,:,1 :min (ni,size (script,3 ))), dim= 3 )
208
+ expected_1D_ptr(1 :size (expected)) = > expected
209
+ slice_1D_ptr(1 :size (slice)) = > slice
210
+ test_diagnosis = test_diagnosis_t( &
211
+ test_passed = all (expected == slice) &
212
+ ,diagnostics_string = " expected slice " // .csv. string_t(expected_1D_ptr) &
213
+ // " ; actual slice " // .csv. string_t(slice_1D_ptr) &
214
+ )
178
215
end function
179
216
180
- function reverse_alphabetize_default_characters () result(test_passes )
181
- logical test_passes
217
+ function reverse_alphabetize_default_characters () result(test_diagnosis )
218
+ type (test_diagnosis_t) test_diagnosis
182
219
integer , parameter :: length = len (" to party!" )
183
220
character (len= length), parameter :: words(* ) = [character (len= length):: " Loddy" ," doddy" ," we" ," like" ," to party!" ]
184
221
character (len= :), allocatable :: my_word, expected_word
@@ -192,7 +229,10 @@ function reverse_alphabetize_default_characters() result(test_passes)
192
229
193
230
call prif_num_images(num_images= n)
194
231
expected_word = maxval (words(1 :min (n, size (words)))) ! this line exposes a flang bug
195
- test_passes = expected_word == my_word
232
+ test_diagnosis = test_diagnosis_t( &
233
+ test_passed = expected_word == my_word &
234
+ ,diagnostics_string = " expected " // expected_word // " ; actual " // my_word &
235
+ )
196
236
end function
197
237
198
- end module prif_co_max_test_m
238
+ end module prif_co_max_test_m
0 commit comments