@@ -5,6 +5,7 @@ module test_specialmatrices
55 use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
66 use stdlib_kinds
77 use stdlib_linalg, only: hermitian
8+ use stdlib_linalg_state, only: linalg_state_type
89 use stdlib_math, only: all_close
910 use stdlib_specialmatrices
1011 implicit none
@@ -18,7 +19,8 @@ contains
1819 type(unittest_type), allocatable, intent(out) :: testsuite(:)
1920
2021 testsuite = [ &
21- new_unittest('tridiagonal', test_tridiagonal) &
22+ new_unittest('tridiagonal', test_tridiagonal), &
23+ new_unittest('tridiagonal error handling', test_tridiagonal_error_handling) &
2224 ]
2325 end subroutine
2426
@@ -65,6 +67,33 @@ contains
6567 #:endfor
6668 end subroutine
6769
70+ subroutine test_tridiagonal_error_handling(error)
71+ !> Error handling
72+ type(error_type), allocatable, intent(out) :: error
73+ #:for k1, t1, s1 in (KINDS_TYPES)
74+ block
75+ integer, parameter :: wp = ${k1}$
76+ integer, parameter :: n = 5
77+ type(tridiagonal_${s1}$_type) :: A
78+ ${t1}$, allocatable :: dl(:), dv(:), du(:)
79+ type(linalg_state_type) :: state
80+ integer :: i
81+
82+ !> Test constructor from arrays.
83+ dl = [(1.0_wp, i = 1, n-2)] ; du = dl
84+ dv = [(2.0_wp, i = 1, n)]
85+ A = tridiagonal(dl, dv, du, state)
86+ call check(error, state%ok(), .false.)
87+ if (allocated(error)) return
88+
89+ !> Test contructor from constants.
90+ A = tridiagonal(dl(1), dv(1), du(1), -n, state)
91+ call check(error, state%ok(), .false.)
92+ if (allocated(error)) return
93+ end block
94+ #:endfor
95+ end subroutine
96+
6897end module
6998
7099
0 commit comments