Skip to content

Commit

Permalink
Added more parse source tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisfish committed Oct 10, 2023
1 parent 4a9e5d5 commit eeb16d4
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 16 deletions.
22 changes: 16 additions & 6 deletions src/parse.f90
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ subroutine handle_camera(child, dects, counts, context, error)
call get_value(child, "trackHistory", trackHistory, .false.)
if(trackHistory)state%trackHistory=.true.
#ifdef _OPENMP
if(trackHistory)error stop "Track history currently incompatable with OpenMP!"
if(trackHistory)then
call make_error(error, "Track history currently incompatable with OpenMP!", -1)
return
end if
#endif
dects(counts) = camera(p1, p2, p3, layer, nbins, maxval, trackHistory)
counts = counts + 1
Expand Down Expand Up @@ -208,7 +211,10 @@ subroutine handle_circle_dect(child, dects, counts, context, error)
call get_value(child, "trackHistory", trackHistory, .false.)
if(trackHistory)state%trackHistory=.true.
#ifdef _OPENMP
if(trackHistory)error stop "Track history currently incompatable with OpenMP!"
if(trackHistory)then
call make_error(error, "Track history currently incompatable with OpenMP!", -1)
return
end if
#endif
dects(counts) = circle_dect(pos, dir, layer, radius, nbins, maxval, trackHistory)
counts = counts + 1
Expand Down Expand Up @@ -237,15 +243,18 @@ subroutine handle_annulus_dect(child, dects, counts, context, error)
call get_value(child, "radius1", radius1)
call get_value(child, "radius2", radius2, origin=origin)
if(radius2 <= radius1)then
print'(a)',context%report("Radii are invalid", origin, "Expected radius2 > radius 1")
stop 1
call make_error(error, context%report("Radii are invalid", origin, "Expected radius2 > radius 1"), -1)
return
end if
call get_value(child, "nbins", nbins, 100)
call get_value(child, "maxval", maxval, 100._wp)
call get_value(child, "trackHistory", trackHistory, .false.)
if(trackHistory)state%trackHistory=.true.
#ifdef _OPENMP
if(trackHistory)error stop "Track history currently incompatable with OpenMP!"
if(trackHistory)then
call make_error(error, "Track history currently incompatable with OpenMP!", -1)
return
end if
#endif
dects(counts) = annulus_dect(pos, dir, layer, radius1, radius2, nbins, maxval, trackHistory)
counts = counts + 1
Expand Down Expand Up @@ -664,7 +673,8 @@ subroutine parse_output(table, error)
if(associated(children))then
nlen = len(children)
if(nlen < 3)then
error stop "Need a vector of size 3 for render_size."
call make_error(error, "Need a vector of size 3 for render_size.", -1)
return
end if
do i = 1, len(children)
call get_value(children, i, state%render_size(i))
Expand Down
253 changes: 243 additions & 10 deletions test/parse/test_parse.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@ subroutine collect_suite2(testsuite)
new_unittest("Test failing: No Source Table", test_no_source_table), &
new_unittest("Test failing: Not valid Source Table 1", test_non_valid_src_table_1), &
new_unittest("Test failing: Not valid Source Table 2", test_non_valid_src_table_2), &
new_unittest("Test failing: Not valid Source Table 3", test_non_valid_src_table_3) &
! new_unittest("Test failing: Not valid Source Table 4", test_non_valid_src_table_4), &
! new_unittest("Test failing: Not valid Source Table 5", test_non_valid_src_table_5), &
! new_unittest("Test failing: Not valid Source Table 6", test_non_valid_src_table_6), &
! new_unittest("Test failing: Not valid Source Table 7", test_non_valid_src_table_7), &
! new_unittest("Test failing: Not valid Source Table 8", test_non_valid_src_table_8), &
! new_unittest("Test failing: Not valid Source Table 9", test_non_valid_src_table_9), &
! new_unittest("Test failing: Not valid Source Table 10", test_non_valid_src_table_10), &
! new_unittest("Test failing: Not valid Source Table 12", test_non_valid_src_table_11), &
! new_unittest("Test failing: Not valid Source Table 11", test_non_valid_src_table_12), &
new_unittest("Test failing: Not valid Source Table 3", test_non_valid_src_table_3), &
new_unittest("Test failing: Not valid Source Table 4", test_non_valid_src_table_4), &
new_unittest("Test failing: Not valid Source Table 5", test_non_valid_src_table_5), &
new_unittest("Test failing: Not valid Source Table 6", test_non_valid_src_table_6), &
new_unittest("Test failing: Not valid Source Table 7", test_non_valid_src_table_7), &
new_unittest("Test failing: Not valid Source Table 8", test_non_valid_src_table_8) &
! new_unittest("Test failing: Not valid detector type", test_non_valid_dect), &
! new_unittest("Test failing: Not valid Annulus dect", test_non_valid_annulus), &
! new_unittest("Test failing: Not valid spectrum type", test_non_valid_spectrum)&
Expand Down Expand Up @@ -173,6 +169,243 @@ subroutine test_non_valid_src_table_3(error)

end subroutine test_non_valid_src_table_3

subroutine test_non_valid_src_table_4(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='blah'"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_4

subroutine test_non_valid_src_table_5(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_5

subroutine test_non_valid_src_table_6(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_6


subroutine test_non_valid_src_table_7(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0]"
write(u,'(a)') "point2 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point3 = [0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_7

subroutine test_non_valid_src_table_8(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point2 = [0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point2 = [0.0, 0.0]"
write(u,'(a)') "point3 = [0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_8

subroutine test_non_valid_src_table_9(error)

use photonMod, only : photon
use detectors, only : dect_array
use piecewiseMod, only : spectrum_t, constant
use tomlf, only: toml_table, toml_error

type(error_type), allocatable, intent(out) :: error

character(len=:),allocatable :: filename
type(toml_table) :: dict
type(photon) :: packet
type(dect_array), allocatable :: dects(:)
type(spectrum_t) :: spectrum
type(toml_error), allocatable :: err
integer :: u

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point2 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point3 = [0.0, 0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

filename = "test/parse/test_fail1.toml"
open(newunit=u, file=filename)
write(u,'(a)') "[source]"
write(u,'(a)') "name='uniform'"
write(u,'(a)') "position=[0.0, 0.0, 0.0]"
write(u,'(a)') "direction='-z'"
write(u,'(a)') "point1 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point2 = [0.0, 0.0, 0.0]"
write(u,'(a)') "point3 = [0.0, 0.0]"
close(u)

call parse_params(filename, packet, dects, spectrum, dict, err)
call check(error, allocated(err), .true.)
if (allocated(error))return

end subroutine test_non_valid_src_table_9

subroutine test_no_source_table(error)

use photonMod, only : photon
Expand Down

0 comments on commit eeb16d4

Please sign in to comment.