Skip to content

Commit 65301b9

Browse files
committed
Add a test for single precision
1 parent 57d517f commit 65301b9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/tests/loadtxt/test_savetxt.f90

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
program test_loadtxt
2-
use iso_fortran_env, only: dp=>real64
2+
use iso_fortran_env, only: sp=>real32, dp=>real64
33
use stdlib_experimental_io, only: loadtxt, savetxt
44
use stdlib_experimental_error, only: assert
55
implicit none
66

7-
call test1()
7+
call test_sp()
8+
call test_dp()
89

910
contains
1011

11-
subroutine test1()
12+
subroutine test_sp()
13+
real(sp) :: d(3, 2), e(2, 3)
14+
real(sp), allocatable :: d2(:, :)
15+
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])
16+
call savetxt("tmp.dat", d)
17+
call loadtxt("tmp.dat", d2)
18+
call assert(all(shape(d2) == [3, 2]))
19+
call assert(all(abs(d-d2) < epsilon(1._sp)))
20+
21+
e = reshape([1, 2, 3, 4, 5, 6], [2, 3])
22+
call savetxt("tmp.dat", e)
23+
call loadtxt("tmp.dat", d2)
24+
call assert(all(shape(d2) == [2, 3]))
25+
call assert(all(abs(e-d2) < epsilon(1._sp)))
26+
end subroutine
27+
28+
29+
subroutine test_dp()
1230
real(dp) :: d(3, 2), e(2, 3)
1331
real(dp), allocatable :: d2(:, :)
1432
d = reshape([1, 2, 3, 4, 5, 6], [3, 2])

0 commit comments

Comments
 (0)