@@ -19,7 +19,7 @@ pure function subject() result(specimen)
1919 specimen = " The csv format"
2020 end function
2121
22- pure function results () result(test_results)
22+ function results () result(test_results)
2323 type (test_result_t), allocatable :: test_results(:)
2424
2525 test_results = [ &
@@ -30,22 +30,51 @@ pure function results() result(test_results)
3030 ]
3131 end function
3232
33- pure function check_csv_reals () result(test_passes)
33+ function check_csv_reals () result(test_passes)
3434 logical test_passes
35- character (len=* ), parameter :: expected_output = " 0.00000000,1.00000000,2.00000000"
36- character (len= len (expected_output)) captured_output
35+ character (len=* ), parameter :: longest_expected_output = " 0.00000000,1.00000000,2.00000000"
36+ character (len= len (longest_expected_output)) captured_output
37+ character (len= :), allocatable :: substring
3738
3839 write (captured_output, fmt = separated_values(separator= " ," , mold= [integer :: ])) [0 .,1 .,2 .]
39- test_passes = expected_output == captured_output
40+
41+ substring = adjustl (trim (captured_output))
42+ associate(leading_real_zero = > index (substring, " 0." ) == 1 )
43+ substring = adjustl (substring(index (substring, " ," )+ 1 :)) ! get remaining string after fierst comma
44+ associate(followed_by_real_one = > index (substring, " 1." ) == 1 )
45+ substring = adjustl (substring(index (substring, " ," )+ 1 :)) ! get remaining string after fierst comma
46+ associate(followed_by_real_two = > index (substring, " 2." ) == 1 )
47+ test_passes = leading_real_zero .and. followed_by_real_one .and. followed_by_real_two
48+ end associate
49+ end associate
50+ end associate
4051 end function
4152
42- pure function check_space_separated_complex () result(test_passes)
53+ function check_space_separated_complex () result(test_passes)
4354 logical test_passes
44- character (len=* ), parameter :: expected_output = " (0.00000000,1.00000000) (1.00000000,0.00000000)"
45- character (len= len (expected_output)) captured_output
55+ character (len=* ), parameter :: longest_expected_output = " (0.00000000,1.00000000) (1.00000000,0.00000000)"
56+ character (len= len (longest_expected_output)) captured_output
57+ complex , parameter :: i = (0 .,1 .), one = (1 .,0 .)
58+ character (len= :), allocatable :: i_imag_part, one_imag_part, i_string, one_string
59+
60+ write (captured_output, fmt = separated_values(separator= " " , mold= [complex :: ])) i,one
61+
62+ i_string = adjustl (trim (captured_output(:index (captured_output," )" ))))
63+ one_string = adjustl (trim (captured_output(len (i_string)+ 1 :)))
4664
47- write (captured_output, fmt = separated_values(separator= " " , mold= [complex :: ])) [(0 .,1 .),(1 .,0 .)]
48- test_passes = expected_output == captured_output
65+ associate( &
66+ i_real_part_zero = > index (i_string," (0." ) == 1 , &
67+ one_real_part_one = > index (one_string," (1." ) == 1 &
68+ )
69+ i_imag_part = adjustl (i_string(index (i_string," ," )+ 1 :index (i_string," )" )- 1 ))
70+ one_imag_part = adjustl (one_string(index (one_string," ," )+ 1 :index (one_string," )" )- 1 ))
71+ associate( &
72+ i_imag_part_one = > index (i_imag_part," 1." ) == 1 , &
73+ one_imag_part_zero = > index (one_imag_part," 0." ) == 1 &
74+ )
75+ test_passes = i_real_part_zero .and. i_imag_part_one .and. one_real_part_one .and. one_imag_part_zero
76+ end associate
77+ end associate
4978 end function
5079
5180 pure function check_new_line_separated_integers () result(test_passes)
0 commit comments