Skip to content

Commit

Permalink
Merge pull request #37 from jacobwilliams/develop
Browse files Browse the repository at this point in the history
adding more tests
  • Loading branch information
jacobwilliams authored Oct 23, 2023
2 parents c094203 + a0424b6 commit b70cc86
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/csv_test3.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ program csv_test3
character(len=30),dimension(:),allocatable :: header, col1
integer :: i
character(len=100) :: tmp_str
integer,dimension(:),allocatable :: int_col
logical,dimension(:),allocatable :: log_col

write(*,*) ''
write(*,*) '============================'
Expand All @@ -25,27 +27,37 @@ program csv_test3
call f%initialize(verbose = .true.)

! open the file
call f%open('test.csv',n_cols=4,status_ok=status_ok)
call f%open('test.csv',n_cols=6,status_ok=status_ok)

! add header
call f%add(['x','y','z','t'])
call f%add(['x ','y ','z ','t ','int','str'])
call f%next_row()

! add some data:
call f%add([1.0_wp,2.0_wp,3.0_wp],real_fmt='(F5.3)')
call f%add(.true.)
call f%add(1)
call f%add('a')
call f%next_row()
call f%add([2.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
call f%add(.false.)
call f%add(1)
call f%add('b')
call f%next_row()
call f%add([3.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
call f%add(.false.)
call f%add(1)
call f%add('c')
call f%next_row()
call f%add([4.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
call f%add(.false.)
call f%add(1)
call f%add('d')
call f%next_row()
call f%add([5.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
call f%add(.false.)
call f%add(1)
call f%add('e')
call f%next_row()

! finished
Expand All @@ -70,12 +82,17 @@ program csv_test3
do i = 1, size(col1)
print "(*(g0))", ">",trim(col1(i)),"<"
end do

do i = 1, 5
write(tmp_str,'(F5.3)') real(i,wp)
if (col1(i) /= tmp_str) error stop 'error converting cell to string:'//tmp_str
end do

call f%get(4,log_col,status_ok)
if (.not. all(log_col .eqv. [.true.,.false.,.false.,.false.,.false.])) error stop 'error getting logical column'

call f%get(5,int_col,status_ok)
if (.not. all(int_col==1)) error stop 'error getting integer column'

! destroy the file
call f%destroy()

Expand Down
34 changes: 34 additions & 0 deletions test/csv_test4.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
!*****************************************************************************************
!>
! Test of [[csv_utilities]].

program csv_test3

use csv_utilities
use iso_fortran_env, only: wp => real64

implicit none

integer,dimension(:),allocatable :: ivec

write(*,*) ''
write(*,*) '============================'
write(*,*) ' csv_test_4 '
write(*,*) '============================'
write(*,*) ''

allocate(ivec(10000))

ivec = 0
ivec(500) = 1

call sort_ascending(ivec)
if (.not. all(ivec(1:10000-1)==0)) error stop 'sort error'
if (ivec(10000)/=1) error stop 'sort error'

ivec = unique(ivec,chunk_size=10)
if (.not. all (ivec == [0,1])) error stop 'unique error'

write(*,*) 'PASSED'

end program csv_test3

0 comments on commit b70cc86

Please sign in to comment.