Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!! !!!!
4 : !!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5 : !!!! !!!!
6 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7 : !!!! !!!!
8 : !!!! This file is part of the ParaMonte library. !!!!
9 : !!!! !!!!
10 : !!!! LICENSE !!!!
11 : !!!! !!!!
12 : !!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13 : !!!! !!!!
14 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 :
17 : !> \brief
18 : !> This module contains implementations of the tests of the procedures under the generic interfaces of [pm_arrayVerbose](@ref pm_arrayVerbose).
19 : !>
20 : !> \todo
21 : !> \phigh The tests in this file still benefit from expansion and improvement.
22 : !>
23 : !> \fintest
24 : !>
25 : !> \author
26 : !> \AmirShahmoradi, September 1, 2017, 11:35 PM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin
27 :
28 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 :
30 : ! Define the equivalence operator.
31 : #if LK_ENABLED
32 : #define IS_EQUAL .eqv.
33 : #else
34 : #define IS_EQUAL ==
35 : #endif
36 : ! Define the slicing rules.
37 : #if SK_ENABLED && D0_ENABLED
38 : #define GET_SIZE(Array, DIM) len(Array, kind = IK)
39 : #define GET_SLICE(i) i:i
40 : #elif D1_ENABLED
41 : #define GET_SIZE(Array, DIM) size(Array, DIM, IK)
42 : #define GET_SLICE(i) i
43 : #elif !D2_ENABLED
44 : #error "Unrecognized interface."
45 : #endif
46 : integer(IK) :: i, iw, dim, counter, csize, csize_ref
47 : integer(IK), allocatable :: weight(:)
48 : #if SK_ENABLED && D0_ENABLED
49 1 : character(:,SKC), allocatable :: arrayVerbose, arrayCompact
50 : #elif SK_ENABLED && D1_ENABLED
51 : character(2,SKC), allocatable :: arrayVerbose(:), arrayCompact(:)
52 : #elif IK_ENABLED && D1_ENABLED
53 : integer(IKC), allocatable :: arrayVerbose(:), arrayCompact(:)
54 : #elif LK_ENABLED && D1_ENABLED
55 : logical(LKC), allocatable :: arrayVerbose(:), arrayCompact(:)
56 : #elif CK_ENABLED && D1_ENABLED
57 : complex(CKC), allocatable :: arrayVerbose(:), arrayCompact(:)
58 : #elif RK_ENABLED && D1_ENABLED
59 : real(RKC), allocatable :: arrayVerbose(:), arrayCompact(:)
60 : #elif SK_ENABLED && D2_ENABLED
61 : character(2,SKC), allocatable :: arrayVerbose(:,:), arrayCompact(:,:)
62 : #elif IK_ENABLED && D2_ENABLED
63 : integer(IKC), allocatable :: arrayVerbose(:,:), arrayCompact(:,:)
64 : #elif LK_ENABLED && D2_ENABLED
65 : logical(LKC), allocatable :: arrayVerbose(:,:), arrayCompact(:,:)
66 : #elif CK_ENABLED && D2_ENABLED
67 : complex(CKC), allocatable :: arrayVerbose(:,:), arrayCompact(:,:)
68 : #elif RK_ENABLED && D2_ENABLED
69 : real(RKC), allocatable :: arrayVerbose(:,:), arrayCompact(:,:)
70 : #else
71 : #error "Unrecognized interface."
72 : #endif
73 39 : assertion = .true._LK
74 :
75 : !%%%%%%%%%%%%%%%%%%%%%%%
76 : #if D0_ENABLED || D1_ENABLED
77 : !%%%%%%%%%%%%%%%%%%%%%%%
78 :
79 20 : dim = 1
80 :
81 : block
82 :
83 20 : call reset()
84 : #if SK_ENABLED && D0_ENABLED
85 1 : allocate(character(0,SKC) :: arrayCompact)
86 : #else
87 19 : allocate(arrayCompact(0))
88 : #endif
89 20 : allocate(weight(GET_SIZE(arrayCompact, dim)))
90 19 : call setUnifRand(weight, -5_IK, 10_IK)
91 19 : csize_ref = sum(weight, mask = weight > 0_IK)
92 :
93 : #if getVerbose_ENABLED
94 39 : arrayVerbose = getVerbose(arrayCompact, weight, csize_ref)
95 20 : csize = GET_SIZE(arrayVerbose, dim)
96 : #elif setVerbose_ENABLED
97 : #endif
98 :
99 20 : assertion = assertion .and. csize == csize_ref
100 20 : call report()
101 20 : call test%assert(assertion, SK_"The verbose size of an empty compact array must be properly set.", int(__LINE__, IK))
102 :
103 39 : assertion = assertion .and. all(shape(arrayVerbose) == csize_ref)
104 20 : call report()
105 20 : call test%assert(assertion, SK_"The shape of the output verbose array must be properly set.", int(__LINE__, IK))
106 :
107 20 : assertion = .true._LK
108 : counter = 0_IK
109 20 : do i = 1, size(weight)
110 20 : do iw = 1, weight(i)
111 0 : counter = counter + 1_IK
112 0 : assertion = assertion .and. arrayVerbose(GET_SLICE(counter)) IS_EQUAL arrayCompact(GET_SLICE(i))
113 0 : call report()
114 0 : call test%assert(assertion, SK_"An empty compact array must be properly expanded.", int(__LINE__, IK))
115 : end do
116 : end do
117 :
118 : end block
119 :
120 1 : block
121 :
122 20 : call reset()
123 : #if SK_ENABLED && D0_ENABLED
124 1 : allocate(character(10,SKC) :: arrayCompact)
125 : #else
126 19 : allocate(arrayCompact(10))
127 : #endif
128 210 : call setUnifRand(arrayCompact)
129 20 : allocate(weight(GET_SIZE(arrayCompact, dim)))
130 220 : call setUnifRand(weight, -5_IK, 10_IK)
131 220 : csize_ref = sum(weight, mask = weight > 0_IK)
132 :
133 : #if getVerbose_ENABLED
134 731 : arrayVerbose = getVerbose(arrayCompact, weight, csize_ref)
135 20 : csize = GET_SIZE(arrayVerbose, dim)
136 : #elif setVerbose_ENABLED
137 : #endif
138 :
139 20 : assertion = assertion .and. csize == csize_ref
140 20 : call report()
141 20 : call test%assert(assertion, SK_"The verbose size of a non-empty compact array must be properly set.", int(__LINE__, IK))
142 :
143 39 : assertion = assertion .and. all(shape(arrayVerbose) == csize_ref)
144 20 : call report()
145 20 : call test%assert(assertion, SK_"The shape of the output verbose array must be properly set.", int(__LINE__, IK))
146 :
147 20 : assertion = .true._LK
148 : counter = 0_IK
149 220 : do i = 1, size(weight)
150 953 : do iw = 1, weight(i)
151 733 : counter = counter + 1_IK
152 733 : assertion = assertion .and. arrayVerbose(GET_SLICE(counter)) IS_EQUAL arrayCompact(GET_SLICE(i))
153 733 : call report()
154 933 : call test%assert(assertion, SK_"A non-empty compact array must be properly expanded.", int(__LINE__, IK))
155 : end do
156 : end do
157 :
158 : end block
159 :
160 : !%%%%%%%%%
161 : #elif D2_ENABLED
162 : !%%%%%%%%%
163 :
164 57 : do dim = 1, 2
165 :
166 : block
167 :
168 38 : call reset()
169 38 : allocate(arrayCompact(0,0))
170 38 : allocate(weight(size(arrayCompact, dim)))
171 38 : call setUnifRand(weight, -5_IK, 10_IK)
172 38 : csize_ref = sum(weight, mask = weight > 0_IK)
173 :
174 : #if getVerbose_ENABLED
175 76 : arrayVerbose = getVerbose(arrayCompact, weight, csize_ref, dim)
176 38 : csize = size(arrayVerbose, dim)
177 : #elif setVerbose_ENABLED
178 : #endif
179 :
180 38 : assertion = assertion .and. csize == csize_ref
181 38 : call report()
182 38 : call test%assert(assertion, SK_"The verbose size of an empty compact array must be properly set.", int(__LINE__, IK))
183 :
184 38 : if (dim == 1_IK) then
185 57 : assertion = assertion .and. all(shape(arrayVerbose) == [csize_ref, size(arrayCompact, 2)])
186 : else
187 57 : assertion = assertion .and. all(shape(arrayVerbose) == [size(arrayCompact, 1), csize_ref])
188 : end if
189 38 : call report()
190 38 : call test%assert(assertion, SK_"The shape of the output verbose array must be properly set.", int(__LINE__, IK))
191 :
192 38 : assertion = .true._LK
193 : counter = 0_IK
194 38 : do i = 1, size(weight)
195 38 : do iw = 1, weight(i)
196 0 : counter = counter + 1_IK
197 0 : if (dim == 1_IK) then
198 0 : assertion = assertion .and. all(arrayVerbose(counter,:) IS_EQUAL arrayCompact(i,:))
199 : else
200 0 : assertion = assertion .and. all(arrayVerbose(:,counter) IS_EQUAL arrayCompact(:,i))
201 : end if
202 0 : call report()
203 0 : call test%assert(assertion, SK_"An empty compact array must be properly expanded.", int(__LINE__, IK))
204 : end do
205 : end do
206 :
207 : end block
208 :
209 19 : block
210 :
211 38 : call reset()
212 64 : allocate(arrayCompact(getUnifRand(0,10), getUnifRand(0,10)))
213 1199 : call setUnifRand(arrayCompact)
214 38 : allocate(weight(size(arrayCompact, dim)))
215 230 : call setUnifRand(weight, -5_IK, 10_IK)
216 230 : csize_ref = sum(weight, mask = weight > 0_IK)
217 :
218 : #if getVerbose_ENABLED
219 3472 : arrayVerbose = getVerbose(arrayCompact, weight, csize_ref, dim)
220 38 : csize = size(arrayVerbose, dim)
221 : #elif setVerbose_ENABLED
222 : #endif
223 :
224 38 : assertion = assertion .and. csize == csize_ref
225 38 : call report()
226 38 : call test%assert(assertion, SK_"The verbose size of a non-empty compact array must be properly set.", int(__LINE__, IK))
227 :
228 38 : if (dim == 1_IK) then
229 57 : assertion = assertion .and. all(shape(arrayVerbose) == [csize_ref, size(arrayCompact, 2)])
230 : else
231 57 : assertion = assertion .and. all(shape(arrayVerbose) == [size(arrayCompact, 1), csize_ref])
232 : end if
233 38 : call report()
234 38 : call test%assert(assertion, SK_"The shape of the output verbose array must be properly set.", int(__LINE__, IK))
235 :
236 38 : assertion = .true._LK
237 : counter = 0_IK
238 230 : do i = 1, size(weight)
239 828 : do iw = 1, weight(i)
240 598 : counter = counter + 1_IK
241 598 : if (dim == 1_IK) then
242 1874 : assertion = assertion .and. all(arrayVerbose(counter,:) IS_EQUAL arrayCompact(i,:))
243 : else
244 1730 : assertion = assertion .and. all(arrayVerbose(:,counter) IS_EQUAL arrayCompact(:,i))
245 : end if
246 598 : call report()
247 790 : call test%assert(assertion, SK_"A non-empty compact array must be properly expanded.", int(__LINE__, IK))
248 : end do
249 : end do
250 :
251 : end block
252 :
253 : end do
254 :
255 : #else
256 : !%%%%%%%%%%%%%%%%%%%%%%%%
257 : #error "Unrecognized interface."
258 : !%%%%%%%%%%%%%%%%%%%%%%%%
259 : #endif
260 :
261 : contains
262 :
263 116 : subroutine reset()
264 116 : if (allocated(weight)) deallocate(weight)
265 116 : if (allocated(arrayVerbose)) deallocate(arrayVerbose)
266 116 : if (allocated(arrayCompact)) deallocate(arrayCompact)
267 116 : end subroutine
268 :
269 1563 : subroutine report()
270 1563 : if (test%traceable .and. .not. assertion) then
271 : ! LCOV_EXCL_START
272 : write(test%disp%unit,"(*(g0,:,', '))")
273 : write(test%disp%unit,"(*(g0,:,', '))") "arrayCompact ", arrayCompact
274 : write(test%disp%unit,"(*(g0,:,', '))") "arrayVerbose ", arrayVerbose
275 : write(test%disp%unit,"(*(g0,:,', '))") "arrayCompact ", arrayCompact
276 : write(test%disp%unit,"(*(g0,:,', '))") "weight ", weight
277 : write(test%disp%unit,"(*(g0,:,', '))") "shape(arrayVerbose)", shape(arrayVerbose)
278 : write(test%disp%unit,"(*(g0,:,', '))") "shape(arrayCompact)", shape(arrayCompact)
279 : write(test%disp%unit,"(*(g0,:,', '))") "size(weight) ", size(weight)
280 : write(test%disp%unit,"(*(g0,:,', '))") "csize_ref ", csize_ref
281 : write(test%disp%unit,"(*(g0,:,', '))") "csize ", csize
282 : write(test%disp%unit,"(*(g0,:,', '))") "dim ", dim
283 : write(test%disp%unit,"(*(g0,:,', '))")
284 : ! LCOV_EXCL_STOP
285 : end if
286 1563 : end subroutine
287 :
288 : #undef GET_SLICE
289 : #undef IS_EQUAL
290 : #undef GET_SIZE
291 : #undef ALL
|