1
- program test_gauss_
1
+ module test_gauss
2
2
use stdlib_kinds, only: dp
3
- use stdlib_error , only: check
3
+ use stdlib_test , only : new_unittest, unittest_type, error_type, check
4
4
use stdlib_quadrature , only: gauss_legendre, gauss_legendre_lobatto
5
5
6
6
implicit none
7
7
8
- call test_gauss
9
- call test_gauss_lobatto
10
8
11
9
contains
12
10
13
- subroutine test_gauss
11
+ ! > Collect all exported unit tests
12
+ subroutine collect_gauss (testsuite )
13
+ ! > Collection of tests
14
+ type (unittest_type), allocatable , intent (out ) :: testsuite(:)
15
+
16
+ testsuite = [ &
17
+ new_unittest(" gauss-analytic" , test_gauss_analytic), &
18
+ new_unittest(" gauss-5" , test_gauss_5), &
19
+ new_unittest(" gauss-32" , test_gauss_32), &
20
+ new_unittest(" gauss-64" , test_gauss_64), &
21
+ new_unittest(" gauss-lobatto-analytic" , test_gauss_lobatto_analytic), &
22
+ new_unittest(" gauss-lobatto-5" , test_gauss_lobatto_5), &
23
+ new_unittest(" gauss-lobatto-32" , test_gauss_lobatto_32), &
24
+ new_unittest(" gauss-lobatto-64" , test_gauss_lobatto_64) &
25
+ ]
26
+ end subroutine
27
+
28
+ subroutine test_gauss_analytic (error )
29
+ ! > Error handling
30
+ type (error_type), allocatable , intent (out ) :: error
31
+
14
32
integer :: i
15
33
real (dp) :: analytic, numeric
16
34
@@ -23,10 +41,19 @@ subroutine test_gauss
23
41
call gauss_legendre(x,w)
24
42
numeric = sum (x** 2 * w)
25
43
! print *, i, numeric
26
- call check(abs (numeric- analytic) < 2 * epsilon (analytic))
44
+ call check(error, abs (numeric- analytic) < 2 * epsilon (analytic))
45
+ if (allocated (error)) return
27
46
end block
28
47
end do
29
48
49
+ end subroutine
50
+
51
+ subroutine test_gauss_5 (error )
52
+ ! > Error handling
53
+ type (error_type), allocatable , intent (out ) :: error
54
+
55
+ integer :: i
56
+
30
57
! test the values of nodes and weights
31
58
i = 5
32
59
block
@@ -44,10 +71,19 @@ subroutine test_gauss
44
71
wref(4 )= 0.47862867049936647_dp
45
72
wref(5 )= 0.23692688505618909_dp
46
73
47
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
48
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
74
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
75
+ if (allocated (error)) return
76
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
49
77
end block
50
78
79
+ end subroutine
80
+
81
+ subroutine test_gauss_32 (error )
82
+ ! > Error handling
83
+ type (error_type), allocatable , intent (out ) :: error
84
+
85
+ integer :: i
86
+
51
87
i = 32
52
88
block
53
89
real (dp), dimension (i) :: x,w,xref,wref
@@ -120,10 +156,19 @@ subroutine test_gauss
120
156
wref(31 )= 0.016274394730905671_dp
121
157
wref(32 )= 0.0070186100094700966_dp
122
158
123
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
124
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
159
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
160
+ if (allocated (error)) return
161
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
125
162
end block
126
163
164
+ end subroutine
165
+
166
+ subroutine test_gauss_64 (error )
167
+ ! > Error handling
168
+ type (error_type), allocatable , intent (out ) :: error
169
+
170
+ integer :: i
171
+
127
172
128
173
i = 64
129
174
block
@@ -262,15 +307,19 @@ subroutine test_gauss
262
307
wref(63 )= 0.0041470332605624676_dp
263
308
wref(64 )= 0.0017832807216964329_dp
264
309
265
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
266
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
310
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
311
+ if (allocated (error)) return
312
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
267
313
end block
268
314
269
315
270
316
271
317
end subroutine
272
318
273
- subroutine test_gauss_lobatto
319
+ subroutine test_gauss_lobatto_analytic (error )
320
+ ! > Error handling
321
+ type (error_type), allocatable , intent (out ) :: error
322
+
274
323
integer :: i
275
324
real (dp) :: analytic, numeric
276
325
@@ -283,10 +332,19 @@ subroutine test_gauss_lobatto
283
332
call gauss_legendre_lobatto(x,w)
284
333
numeric = sum (x** 2 * w)
285
334
! print *, i, numeric
286
- call check(abs (numeric- analytic) < 2 * epsilon (analytic))
335
+ call check(error, abs (numeric- analytic) < 2 * epsilon (analytic))
336
+ if (allocated (error)) return
287
337
end block
288
338
end do
289
339
340
+ end subroutine
341
+
342
+ subroutine test_gauss_lobatto_5 (error )
343
+ ! > Error handling
344
+ type (error_type), allocatable , intent (out ) :: error
345
+
346
+ integer :: i
347
+
290
348
291
349
! test the values of nodes and weights
292
350
i = 5
@@ -308,10 +366,19 @@ subroutine test_gauss_lobatto
308
366
wref(5 )= 0.10000000000000000_dp
309
367
310
368
311
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
312
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
369
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
370
+ if (allocated (error)) return
371
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
313
372
end block
314
373
374
+ end subroutine
375
+
376
+ subroutine test_gauss_lobatto_32 (error )
377
+ ! > Error handling
378
+ type (error_type), allocatable , intent (out ) :: error
379
+
380
+ integer :: i
381
+
315
382
i = 32
316
383
block
317
384
real (dp), dimension (i) :: x,w,xref,wref
@@ -383,10 +450,19 @@ subroutine test_gauss_lobatto
383
450
wref(31 )= 0.012398106501373844_dp
384
451
wref(32 )= 0.0020161290322580645_dp
385
452
386
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
387
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
453
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
454
+ if (allocated (error)) return
455
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
388
456
end block
389
457
458
+ end subroutine
459
+
460
+ subroutine test_gauss_lobatto_64 (error )
461
+ ! > Error handling
462
+ type (error_type), allocatable , intent (out ) :: error
463
+
464
+ integer :: i
465
+
390
466
391
467
i = 64
392
468
block
@@ -524,10 +600,38 @@ subroutine test_gauss_lobatto
524
600
wref(63 )= 0.0030560082449124904_dp
525
601
wref(64 )= 0.00049603174603174603_dp
526
602
527
- call check (all (abs (x- xref) < 2 * epsilon (x(1 ))))
528
- call check (all (abs (w- wref) < 2 * epsilon (w(1 ))))
603
+ call check(error, all (abs (x- xref) < 2 * epsilon (x(1 ))))
604
+ if (allocated (error)) return
605
+ call check(error, all (abs (w- wref) < 2 * epsilon (w(1 ))))
529
606
end block
530
607
531
608
end subroutine
532
609
610
+ end module
611
+
612
+
613
+ program tester
614
+ use , intrinsic :: iso_fortran_env, only : error_unit
615
+ use stdlib_test, only : run_testsuite, new_testsuite, testsuite_type
616
+ use test_gauss, only : collect_gauss
617
+ implicit none
618
+ integer :: stat, is
619
+ type (testsuite_type), allocatable :: testsuites(:)
620
+ character (len=* ), parameter :: fmt = ' ("#", *(1x, a))'
621
+
622
+ stat = 0
623
+
624
+ testsuites = [ &
625
+ new_testsuite(" gauss" , collect_gauss) &
626
+ ]
627
+
628
+ do is = 1 , size (testsuites)
629
+ write (error_unit, fmt) " Testing:" , testsuites(is)% name
630
+ call run_testsuite(testsuites(is)% collect, error_unit, stat)
631
+ end do
632
+
633
+ if (stat > 0 ) then
634
+ write (error_unit, ' (i0, 1x, a)' ) stat, " test(s) failed!"
635
+ error stop
636
+ end if
533
637
end program
0 commit comments