Skip to content

Commit 551ec6d

Browse files
committed
added first tests for gaussian quadrature functions
1 parent ce62e1f commit 551ec6d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/tests/quadrature/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ADDTEST(trapz)
22
ADDTEST(simps)
3+
ADDTEST(gauss)

src/tests/quadrature/Makefile.manual

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
PROGS_SRC = test_trapz.f90
2+
PROGS_SRC = test_simps.f90
3+
PROGS_SRC = test_gauss.f90
24

35
include ../Makefile.manual.test.mk

src/tests/quadrature/test_gauss.f90

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
program test_gauss_
2+
use stdlib_kinds, only: dp
3+
use stdlib_error, only: check
4+
use stdlib_quadrature , only: gauss_legendre, gauss_legendre_lobatto
5+
6+
implicit none
7+
8+
call test_gauss
9+
call test_gauss_lobatto
10+
11+
contains
12+
13+
subroutine test_gauss
14+
integer :: i
15+
real(dp) :: analytic, numeric
16+
17+
! x**2 from -1 to 1
18+
analytic = 2.0_dp/3.0_dp
19+
do i=2,6
20+
block
21+
real(dp), dimension(i) :: x,w
22+
call gauss_legendre(x,w)
23+
numeric = sum(x**2 * w)
24+
!print *, i, numeric
25+
call check(abs(numeric-analytic) < 2*epsilon(analytic))
26+
end block
27+
end do
28+
29+
end subroutine
30+
31+
subroutine test_gauss_lobatto
32+
end subroutine
33+
34+
end program

0 commit comments

Comments
 (0)