Skip to content

Commit

Permalink
adding TODOs and initial tests for fetchHerny and accessory functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Oct 12, 2021
1 parent ea61f16 commit be59c65
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/fetchHenry.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## TODO: better checking of inputs, as the entitre DB could be downloaded by accident!!
## TODO: better checking of inputs, as the entire DB could be downloaded by accident!!

## TODO:

# replace ddply -> split/lapply/rbind | data.table
# replace join -> base::merge(..., sort = FALSE)

# # TODO: finish this
# .summarizeSoilVWC <- function(soilVWC.data) {
Expand Down Expand Up @@ -95,10 +98,12 @@ summarizeSoilTemperature <- function(soiltemp.data) {

month2season <- function(x) {
season <- rep(NA, times=length(x))

season[x %in% c('Jun', 'Jul', 'Aug')] <- 'Summer'
season[x %in% c('Dec', 'Jan', 'Feb')] <- 'Winter'
season[x %in% c('Mar', 'Apr', 'May')] <- 'Spring'
season[x %in% c('Sep', 'Oct', 'Nov')] <- 'Fall'

# fix factor levels for season
season <- factor(season, levels=c('Winter', 'Spring', 'Summer', 'Fall'))
return(season)
Expand Down Expand Up @@ -139,10 +144,12 @@ month2season <- function(x) {
# must have data, otherwise do nothing
# when sensor data are missing, sensor.data is a list of length 0
if(length(sensor.data) > 0) {

sensor.data$date_time <- as.POSIXct(sensor.data$date_time)
sensor.data$year <- as.integer(format(sensor.data$date_time, "%Y"))
sensor.data$doy <- as.integer(format(sensor.data$date_time, "%j"))
sensor.data$month <- format(sensor.data$date_time, "%b")

# re-level months
sensor.data$month <- factor(sensor.data$month, levels=c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'))

Expand Down
71 changes: 71 additions & 0 deletions tests/testthat/test-fetchHenry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
context("fetchHenry and related")




test_that("month2season() works as expected", {

x <- c('Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May')
res <- month2season(x)

# classification
expect_equal(
as.character(res),
c("Summer", "Summer", "Summer", "Fall", "Fall", "Fall", "Winter", "Winter", "Winter", "Spring", "Spring", "Spring")
)

# factor levels
expect_equal(
levels(res),
c("Winter", "Spring", "Summer", "Fall")
)

# bogus input
expect_true(
is.na(month2season('da'))
)

})



test_that("summarizeSoilTemperature() works as expected", {

expect_true(TRUE)

})


test_that(".fill_missing_days() works as expected", {

expect_true(TRUE)

})


test_that(".formatDates() works as expected", {

expect_true(TRUE)

})

test_that(".formatDates() works as expected", {

expect_true(TRUE)

})


test_that("fetchHenry() works as expected", {

expect_true(TRUE)

})








0 comments on commit be59c65

Please # to comment.