-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests and small aspects to articles
- Loading branch information
Showing
7 changed files
with
311 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
test_that("aggregate_Date works", { | ||
dates <- sample.data.environment | ||
#aggregate_Date works | ||
expect_no_error(aggregate_Date(dates)) | ||
|
||
#only one day left | ||
dates_agg <- aggregate_Date(dates) | ||
expect_equal(lubridate::date(dates_agg$Datetime) %>% unique() %>% length(), 1) | ||
#leaving unit = "none" (default) yields different results depending on Id | ||
expect_equal(dates_agg %>% dominant_epoch() %>% | ||
dplyr::pull(dominant.epoch) %>% | ||
as.numeric, | ||
c(30, 10) | ||
) | ||
#changing the date.handler to max works | ||
dates_agg2 <- aggregate_Date(dates, date.handler = max) | ||
expect_equal(lubridate::date(dates_agg2$Datetime) %>% | ||
unique() %>% | ||
as.character(), | ||
"2023-08-20") | ||
#changing the numeric unit works | ||
dates_agg3 <- aggregate_Date(dates, unit = "15 mins") | ||
expect_equal(dates_agg3 %>% | ||
count_difftime() %>% | ||
dplyr::pull(difftime) %>% | ||
as.numeric, | ||
c(15*60, 15*60) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
test_that("repeat_date and next date works", { | ||
#some example datetimes | ||
dates <- tibble::tibble( | ||
Datetime = as.POSIXct( | ||
c("2023-08-20 10:00:00", | ||
"2023-08-20 10:15:00", | ||
"2023-08-20 10:30:00", | ||
"2023-08-20 10:45:00" | ||
) | ||
) | ||
) | ||
|
||
#repeat_date works | ||
expect_equal(nrow(repeat_date(dates)), 2*nrow(dates)) | ||
expect_equal(repeat_date(dates) %>% | ||
dplyr::pull(Datetime) %>% | ||
lubridate::date() %>% | ||
unique() %>% as.character(), | ||
c("2023-08-20", "2023-08-21")) | ||
expect_equal(repeat_date(dates) %>% length(), 2) | ||
expect_equal(repeat_date(dates) %>% dplyr::group_vars(), "Date.data") | ||
expect_true(repeat_date(dates) %>% | ||
create_Timedata() %>% | ||
dplyr::pull(Time.data) %>% {all(.[1:4] == .[5:8])}) | ||
|
||
#next_date works | ||
next_dates <- next_date(repeat_date(dates) %>% dplyr::ungroup()) | ||
expect_equal(nrow(next_dates), 3*nrow(dates)) | ||
expect_equal(next_dates %>% | ||
dplyr::pull(Datetime) %>% | ||
lubridate::date() %>% unique() %>% as.character(), | ||
c("2023-08-20", "2023-08-21")) | ||
expect_equal(next_dates %>% | ||
dplyr::pull(Datetime) %>% | ||
lubridate::date() %>% table() %>% unname() %>% as.numeric(), | ||
c(4, 8)) | ||
expect_equal(next_dates %>% length(), 2) | ||
expect_equal(next_dates %>% dplyr::group_vars(), "Date.data") | ||
}) | ||
|
||
test_that("double_date works", { | ||
#some example datetimes | ||
dates <- tibble::tibble( | ||
Datetime = as.POSIXct( | ||
c("2023-08-20 10:00:00", | ||
"2023-08-20 10:15:00", | ||
"2023-08-20 10:30:00", | ||
"2023-08-20 10:45:00" | ||
) | ||
) | ||
) | ||
next_dates <- next_date(repeat_date(dates) %>% dplyr::ungroup()) | ||
|
||
#double_date correctly identifies the correct type of date | ||
expect_equal(double_date(dates), repeat_date(dates)) | ||
expect_equal(double_date(repeat_date(dates) %>% dplyr::ungroup()), | ||
next_dates) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.