Skip to content

Commit

Permalink
test: add more testing of datetime basic addition
Browse files Browse the repository at this point in the history
  • Loading branch information
smwesten-usgs committed Jun 20, 2023
1 parent 6810c59 commit e79340c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion test/unit_tests/fruit_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ program tests
call run_test_case(test_datetime_illegal_values,"datetime: parse with non-existant day value")
call run_test_case(test_datetime_basic_mangled_dateparse,"datetime: parse with default mm/dd/yyyy date format, missing '0' values in month and day")
call run_test_case(test_datetime_custom_dateparse,"datetime: parse with custom yyyy-mm-dd date format")
call run_test_case(test_datetime_addition,"datetime: add 5 to Julian day and return the correct Gregorian date")
call run_test_case(test_datetime_addition_day,"datetime: add 5 to Julian day and return the correct Gregorian date")
call run_test_case(test_datetime_julian_date_illegal_month,"datetime: supply illegal month value to Julian Date routine")
call run_test_case(test_datetime_julian_date_illegal_day,"datetime: supply illegal day value to Julian Date routine")
call run_test_case(test_datetime_julian_date_illegal_month_day,"datetime: supply illegal month and day value to Julian Date routine")
call run_test_case(test_count_leap_days_between_dates,"test_count_leap_days_between_dates")
call run_test_case(test_datetime_basic_addition,"datetime: add known quantity to datetime object")

! test_exceptions__index_values_valid.F90:
call run_test_case(test_check_array_bounds_1d,"test_check_array_bounds_1d")
Expand Down
25 changes: 22 additions & 3 deletions test/unit_tests/test_datetime.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end subroutine test_datetime_custom_dateparse

!-------------------------------------------------------------------------------

subroutine test_datetime_addition
subroutine test_datetime_addition_day
! datetime: add 5 to Julian day and return the correct Gregorian date
type (DATETIME_T) :: dt
integer :: indx
Expand All @@ -106,7 +106,7 @@ subroutine test_datetime_addition
call assert_equals (5, int(dt%iDay))
call assert_equals (2000, int(dt%iYear))

end subroutine test_datetime_addition
end subroutine test_datetime_addition_day

!-------------------------------------------------------------------------------

Expand Down Expand Up @@ -160,7 +160,7 @@ end subroutine test_datetime_julian_date_illegal_month_day

subroutine test_count_leap_days_between_dates

type (DATETIME_T) :: dt_min, dt_max
type (DATETIME_T) :: dt_min, dt_max, dt_new
integer :: num_leap_days

call dt_min%setDateFormat("YYYY-MM-DD")
Expand Down Expand Up @@ -217,5 +217,24 @@ subroutine test_count_leap_days_between_dates
call assert_equals (30, num_leap_days)

end subroutine test_count_leap_days_between_dates

!-------------------------------------------------------------------------------

subroutine test_datetime_basic_addition
! datetime: add known quantity to datetime object
type (DATETIME_T) :: dt_min, dt_new

! set dt_min to 1950-01-01
call dt_min%parseDate("1950-01-01", sFilename=trim(__FILE__), iLineNumber=__LINE__)

dt_new = dt_min + 11323.5
call dt_new%calcGregorianDate()

! new date value should be 1981-01-01
call assert_equals(1, int(dt_new%iMonth))
call assert_equals(1, int(dt_new%iDay))
call assert_equals(1981, int(dt_new%iYear))

end subroutine test_datetime_basic_addition

end module test_datetime
6 changes: 6 additions & 0 deletions test/unit_tests/test_exceptions__index_values_valid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ subroutine test_check_array_bounds_1d
call assert_equals( TRUE, logical(index_values_valid(integer_values, 25)) )
call assert_equals( FALSE, logical(index_values_valid(integer_values, 616)) )

call assert_equals( TRUE, logical(index_values_valid(float_values, 23)) )
call assert_equals( FALSE, logical(index_values_valid(float_values, 24)) )

call assert_equals( TRUE, logical(index_values_valid(double_values, 42)) )
call assert_equals( FALSE, logical(index_values_valid(double_values, 43)) )

end subroutine test_check_array_bounds_1d

end module test_exceptions

0 comments on commit e79340c

Please sign in to comment.