Skip to content

Commit

Permalink
Merge pull request #11 from poissonconsulting/f-ghissue10
Browse files Browse the repository at this point in the history
add tests for atu day picking with simplified data
  • Loading branch information
joethorley committed Jul 10, 2024
2 parents 1246652 + 0697343 commit efe37f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/date-atus.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Calculate Date of Accumulated Thermal Units (ATUs)
#'
#' Calculates the date on which a specified number of Accumulated Thermal Units (ATUs)
#' are exceeded.
#' are meet or exceeded.
#'
#' @inheritParams params
#' @return A tibble with four columns `year`, `start_date`, `end_date` and `atus`.
Expand Down
2 changes: 1 addition & 1 deletion man/date_atus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/_snaps/date-atus.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,25 @@
<int> <date> <date> <dbl>
1 2019 1972-01-01 NA NA

# date_atus picks correct day to exceed 20

Code
date_atus
Output
# A tibble: 1 x 4
# Groups: year [1]
year start_date end_date atus
<int> <date> <date> <dbl>
1 2019 1972-01-01 1972-01-02 20

# date_atus picks correct day to exceed 600

Code
date_atus
Output
# A tibble: 1 x 4
# Groups: year [1]
year start_date end_date atus
<int> <date> <date> <dbl>
1 2019 1972-01-01 1972-01-31 600

30 changes: 30 additions & 0 deletions tests/testthat/test-date-atus.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,33 @@ test_that("date_atus NA if not enough data to reach", {
date_atus
})
})

test_that("date_atus picks correct day to exceed 20", {
data <- tibble::tibble(
date = seq.Date(
from = as.Date("2019-01-01"),
to = as.Date("2019-12-31"),
by = "day"),
temperature = c(0, rep(20, 364)))

date_atus <- date_atus(data, start_date = as.Date("2019-01-01"), atu = 20)

expect_snapshot({
date_atus
})
})

test_that("date_atus picks correct day to exceed 600", {
data <- tibble::tibble(
date = seq.Date(
from = as.Date("2019-01-01"),
to = as.Date("2019-12-31"),
by = "day"),
temperature = c(0, rep(20, 364)))

date_atus <- date_atus(data, start_date = as.Date("2019-01-01"), atu = 600)

expect_snapshot({
date_atus
})
})

0 comments on commit efe37f1

Please sign in to comment.