Skip to content

Commit 4ef4fb0

Browse files
committed
add linalg_state tests
1 parent 31cb5eb commit 4ef4fb0

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

test/linalg/test_linalg.fypp

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module test_linalg
55
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
66
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
77
use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product, kronecker_product
8+
use stdlib_linalg_state
89

910
implicit none
1011

@@ -49,9 +50,9 @@ contains
4950
new_unittest("trace_int16", test_trace_int16), &
5051
new_unittest("trace_int32", test_trace_int32), &
5152
new_unittest("trace_int64", test_trace_int64), &
52-
#:for k1, t1 in RCI_KINDS_TYPES
53+
#:for k1, t1 in RCI_KINDS_TYPES
5354
new_unittest("kronecker_product_${t1[0]}$${k1}$", test_kronecker_product_${t1[0]}$${k1}$), &
54-
#:endfor
55+
#:endfor
5556
new_unittest("outer_product_rsp", test_outer_product_rsp), &
5657
new_unittest("outer_product_rdp", test_outer_product_rdp), &
5758
new_unittest("outer_product_rqp", test_outer_product_rqp), &
@@ -71,7 +72,8 @@ contains
7172
new_unittest("cross_product_int8", test_cross_product_int8), &
7273
new_unittest("cross_product_int16", test_cross_product_int16), &
7374
new_unittest("cross_product_int32", test_cross_product_int32), &
74-
new_unittest("cross_product_int64", test_cross_product_int64) &
75+
new_unittest("cross_product_int64", test_cross_product_int64), &
76+
new_unittest("state_handling", test_state_handling) &
7577
]
7678

7779
end subroutine collect_linalg
@@ -560,7 +562,7 @@ contains
560562

561563

562564
#:for k1, t1 in RCI_KINDS_TYPES
563-
subroutine test_kronecker_product_${t1[0]}$${k1}$(error)
565+
subroutine test_kronecker_product_${t1[0]}$${k1}$(error)
564566
!> Error handling
565567
type(error_type), allocatable, intent(out) :: error
566568
integer, parameter :: m1 = 1, n1 = 2, m2 = 2, n2 = 3
@@ -593,7 +595,7 @@ contains
593595
! Expected: C = [1*B, 2*B] = [[1,2,3, 2,4,6], [2,4,6, 4, 8, 12]]
594596

595597
end subroutine test_kronecker_product_${t1[0]}$${k1}$
596-
#:endfor
598+
#:endfor
597599

598600
subroutine test_outer_product_rsp(error)
599601
!> Error handling
@@ -911,6 +913,73 @@ contains
911913
#:endif
912914
end subroutine test_cross_product_cqp
913915

916+
subroutine test_state_handling(error)
917+
!> Error handling
918+
type(error_type), allocatable, intent(out) :: error
919+
920+
type(linalg_state) :: state,state_out
921+
922+
state = linalg_state(LINALG_SUCCESS,' 32-bit real: ',1.0_sp)
923+
call check(error, &
924+
state%message==' 32-bit real: 1.00000000E+00', &
925+
"malformed state message with 32-bit reals.")
926+
if (allocated(error)) return
927+
928+
state = linalg_state(LINALG_SUCCESS,' 64-bit real: ',1.0_dp)
929+
call check(error, &
930+
state%message==' 64-bit real: 1.0000000000000000E+000', &
931+
"malformed state message with 64-bit reals.")
932+
if (allocated(error)) return
933+
934+
#:if WITH_QP
935+
state = linalg_state(LINALG_SUCCESS,' 128-bit real: ',1.0_qp)
936+
call check(error, &
937+
state%message==' 128-bit real: 1.00000000000000000000000000000000000E+0000', &
938+
"malformed state message with 128-bit reals.")
939+
if (allocated(error)) return
940+
#:endif
941+
942+
state = linalg_state(LINALG_SUCCESS,' 32-bit complex: ',(1.0_sp,1.0_sp))
943+
call check(error, &
944+
state%message==' 32-bit complex: (1.00000000E+00,1.00000000E+00)', &
945+
"malformed state message with 32-bit complex: "//trim(state%message))
946+
if (allocated(error)) return
947+
948+
state = linalg_state(LINALG_SUCCESS,' 64-bit complex: ',(1.0_dp,1.0_dp))
949+
call check(error, &
950+
state%message==' 64-bit complex: (1.0000000000000000E+000,1.0000000000000000E+000)', &
951+
"malformed state message with 64-bit complex.")
952+
if (allocated(error)) return
953+
954+
#:if WITH_QP
955+
state = linalg_state(LINALG_SUCCESS,'128-bit complex: ',(1.0_qp,1.0_qp))
956+
call check(error, state%message== &
957+
'128-bit complex: (1.00000000000000000000000000000000000E+0000,1.00000000000000000000000000000000000E+0000)', &
958+
"malformed state message with 128-bit complex.")
959+
960+
#:endif
961+
962+
state = linalg_state(LINALG_SUCCESS,' 32-bit array: ',v1=[(1.0_sp,0.0_sp),(0.0_sp,1.0_sp)])
963+
call check(error, state%message== &
964+
' 32-bit array: [(1.00000000E+00,0.00000000E+00) (0.00000000E+00,1.00000000E+00)]', &
965+
"malformed state message with 32-bit real array.")
966+
if (allocated(error)) return
967+
968+
!> State flag with location
969+
state = linalg_state('test_formats',LINALG_SUCCESS,' 32-bit real: ',1.0_sp)
970+
call check(error, &
971+
state%print()=='[test_formats] returned Success!', &
972+
"malformed state message with 32-bit real and location.")
973+
if (allocated(error)) return
974+
975+
!> Test error handling procedure
976+
call linalg_error_handling(state,state_out)
977+
call check(error, state%print()==state_out%print(), &
978+
"malformed state message on return from error handling procedure.")
979+
980+
end subroutine test_state_handling
981+
982+
914983
pure recursive function catalan_number(n) result(value)
915984
integer, intent(in) :: n
916985
integer :: value

0 commit comments

Comments
 (0)