From c72cf7536de700cd4f977011a41bb7fab67803c5 Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 14 Aug 2024 18:54:00 +0000 Subject: [PATCH 1/4] weird recursion test --- tests/testthat/test-derive_vars_dt.R | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/testthat/test-derive_vars_dt.R b/tests/testthat/test-derive_vars_dt.R index 2d4b33b4cc..d90240d4dc 100644 --- a/tests/testthat/test-derive_vars_dt.R +++ b/tests/testthat/test-derive_vars_dt.R @@ -292,6 +292,71 @@ test_that("compute_dtf Test 13: compute DTF", { ) }) +# restrict_imputed_dtc_dt ---- +test_that("", { + imputed_dtc <- impute_dtc_dt( + input, + min_dates = list( + c( + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06") + ), + c( + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06") + ) + ), + highest_imputation = "Y", + date_imputation = "first" + ) + restricted <- restrict_imputed_dtc_dt( + input, + imputed_dtc = imputed_dtc, + min_dates = list( + c( + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06") + ), + c( + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06") + ) + ), + max_dates = list( + c( + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06"), + ymd("2019-07-06") + ), + c( + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06"), + ymd("2019-06-06") + ) + ) + ) + expect_equal( + restricted, + c("2019-07-18", "2019-06-06", "2019-06-06", "2019-07-06", "2019-06-06") + ) +}) + # derive_vars_dt ---- date <- tibble::tribble( From 741b8b8f17bdc2dbacf92f298b58a3f7b8fe66ee Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Thu, 15 Aug 2024 19:17:27 +0000 Subject: [PATCH 2/4] remove extra examples --- tests/testthat/test-derive_vars_dt.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_vars_dt.R b/tests/testthat/test-derive_vars_dt.R index d90240d4dc..16b65b200d 100644 --- a/tests/testthat/test-derive_vars_dt.R +++ b/tests/testthat/test-derive_vars_dt.R @@ -634,4 +634,4 @@ test_that("derive_vars_dt Test 24: Supplying both min/max dates for highest_impu expect_dfs_equal(actual, expected, keys = c("ASTDT", "ASTDTF")) }) -rm(input, input_warnings) +rm(input, input_warnings, inputdt, inputdtc, date) From ecf8215471395ca206de1e0e132d3a3958ed9120 Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 16 Oct 2024 14:16:53 +0000 Subject: [PATCH 3/4] add news and update spelling --- NEWS.md | 2 ++ inst/WORDLIST | 1 + 2 files changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 8a050ff2c0..0482f57b92 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,8 @@
Developer Notes +- Created unit tests for developer internal function `restricted_imputed_dtc_dt()` (#2495) +
# admiral 1.1.1 diff --git a/inst/WORDLIST b/inst/WORDLIST index ad1b8d709e..465167679b 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -193,6 +193,7 @@ README Rahal Ratford Romain +Rothstein SCE SCN SCOPEN From 7a11fab41b82269c9582188262e2fdc5a939075a Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Thu, 17 Oct 2024 14:27:32 +0000 Subject: [PATCH 4/4] appropriate testthat format --- tests/testthat/test-derive_vars_dt.R | 47 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/testthat/test-derive_vars_dt.R b/tests/testthat/test-derive_vars_dt.R index 16b65b200d..bcac8e9063 100644 --- a/tests/testthat/test-derive_vars_dt.R +++ b/tests/testthat/test-derive_vars_dt.R @@ -293,7 +293,8 @@ test_that("compute_dtf Test 13: compute DTF", { }) # restrict_imputed_dtc_dt ---- -test_that("", { +## Test 14: restrict_imputed_dtc_dt works as expected ---- +test_that("restrict_imputed_dtc_dt Test 14: restrict_imputed_dtc_dt works as expected", { imputed_dtc <- impute_dtc_dt( input, min_dates = list( @@ -368,8 +369,8 @@ date <- tibble::tribble( "2019---07" ) -## Test 14: default behavior ---- -test_that("derive_vars_dt Test 14: default behavior", { +## Test 15: default behavior ---- +test_that("derive_vars_dt Test 15: default behavior", { expected_output <- tibble::tribble( ~XXSTDTC, ~ASTDT, "2019-07-18T15:25:40", as.Date("2019-07-18"), @@ -392,8 +393,8 @@ test_that("derive_vars_dt Test 14: default behavior", { ) }) -## Test 15: no date imputation, add DTF ---- -test_that("derive_vars_dt Test 15: no date imputation, add DTF", { +## Test 16: no date imputation, add DTF ---- +test_that("derive_vars_dt Test 16: no date imputation, add DTF", { expected_output <- tibble::tribble( ~XXSTDTC, ~ASTDT, ~ASTDTF, "2019-07-18T15:25:40", as.Date("2019-07-18"), NA_character_, @@ -417,8 +418,8 @@ test_that("derive_vars_dt Test 15: no date imputation, add DTF", { ) }) -## Test 16: date imputed to first, auto DTF ---- -test_that("derive_vars_dt Test 16: date imputed to first, auto DTF", { +## Test 17: date imputed to first, auto DTF ---- +test_that("derive_vars_dt Test 17: date imputed to first, auto DTF", { expected_output <- tibble::tribble( ~XXSTDTC, ~ASTDT, ~ASTDTF, "2019-07-18T15:25:40", as.Date("2019-07-18"), NA_character_, @@ -443,8 +444,8 @@ test_that("derive_vars_dt Test 16: date imputed to first, auto DTF", { ) }) -## Test 17: date imputed to last, no DTF ---- -test_that("derive_vars_dt Test 17: date imputed to last, no DTF", { +## Test 18: date imputed to last, no DTF ---- +test_that("derive_vars_dt Test 18: date imputed to last, no DTF", { expected_output <- tibble::tribble( ~XXSTDTC, ~AENDT, "2019-07-18T15:25:40", as.Date("2019-07-18"), @@ -470,8 +471,8 @@ test_that("derive_vars_dt Test 17: date imputed to last, no DTF", { ) }) -## Test 18: NA imputation for highest_imputation = Y & max_dates ---- -test_that("derive_vars_dt Test 18: NA imputation for highest_imputation = Y & max_dates", { +## Test 19: NA imputation for highest_imputation = Y & max_dates ---- +test_that("derive_vars_dt Test 19: NA imputation for highest_imputation = Y & max_dates", { actual <- data.frame( AESTDTC = c(NA_character_, NA_character_), TRTSDT = c(ymd("2022-01-01"), NA) @@ -496,8 +497,8 @@ test_that("derive_vars_dt Test 18: NA imputation for highest_imputation = Y & ma expect_dfs_equal(actual, expected, keys = c("ASTDT", "ASTDTF")) }) -## Test 19: NA imputation for highest_imputation = Y & max_dates but date_imputation = first ---- -test_that("derive_vars_dt Test 19: NA imputation for highest_imputation = Y & max_dates but date_imputation = first", { # nolint +## Test 20: NA imputation for highest_imputation = Y & max_dates but date_imputation = first ---- +test_that("derive_vars_dt Test 20: NA imputation for highest_imputation = Y & max_dates but date_imputation = first", { # nolint expect_snapshot( data.frame( AESTDTC = c(NA_character_, NA_character_), @@ -515,8 +516,8 @@ test_that("derive_vars_dt Test 19: NA imputation for highest_imputation = Y & ma ) }) -## Test 20: NA imputation for highest_imputation = Y & min_dates ---- -test_that("derive_vars_dt Test 20: NA imputation for highest_imputation = Y & min_dates", { +## Test 21: NA imputation for highest_imputation = Y & min_dates ---- +test_that("derive_vars_dt Test 21: NA imputation for highest_imputation = Y & min_dates", { actual <- data.frame( AESTDTC = c(NA_character_, NA_character_), TRTSDT = c(ymd("2022-01-01"), NA) @@ -541,8 +542,8 @@ test_that("derive_vars_dt Test 20: NA imputation for highest_imputation = Y & mi expect_dfs_equal(actual, expected, keys = c("ASTDT", "ASTDTF")) }) -## Test 21: NA imputation for highest_imputation = Y & min_dates but date_imputation = last ---- -test_that("derive_vars_dt Test 21: NA imputation for highest_imputation = Y & min_dates but date_imputation = last", { # nolint +## Test 22: NA imputation for highest_imputation = Y & min_dates but date_imputation = last ---- +test_that("derive_vars_dt Test 22: NA imputation for highest_imputation = Y & min_dates but date_imputation = last", { # nolint expect_snapshot( data.frame( AESTDTC = c(NA_character_, NA_character_), @@ -560,8 +561,8 @@ test_that("derive_vars_dt Test 21: NA imputation for highest_imputation = Y & mi ) }) -## Test 22: NA imputation for highest_imputation = Y but null min/max dates fails ---- -test_that("derive_vars_dt Test 22: NA imputation for highest_imputation = Y but null min/max dates fails", { # nolint +## Test 23: NA imputation for highest_imputation = Y but null min/max dates fails ---- +test_that("derive_vars_dt Test 23: NA imputation for highest_imputation = Y but null min/max dates fails", { # nolint expect_snapshot( data.frame( AESTDTC = c(NA_character_, NA_character_), @@ -579,8 +580,8 @@ test_that("derive_vars_dt Test 22: NA imputation for highest_imputation = Y but ) }) -## Test 23: Supplying both min/max dates for highest_imputation = Y works ---- -test_that("derive_vars_dt Test 23: Supplying both min/max dates for highest_imputation = Y works", { # nolint +## Test 24: Supplying both min/max dates for highest_imputation = Y works ---- +test_that("derive_vars_dt Test 24: Supplying both min/max dates for highest_imputation = Y works", { # nolint actual <- data.frame( AESTDTC = c(NA_character_, NA_character_), TRTSDT = c(ymd("2022-01-01"), NA), @@ -606,8 +607,8 @@ test_that("derive_vars_dt Test 23: Supplying both min/max dates for highest_impu expect_dfs_equal(actual, expected, keys = c("ASTDT", "ASTDTF")) }) -## Test 24: Supplying both min/max dates for highest_imputation = Y works ---- -test_that("derive_vars_dt Test 24: Supplying both min/max dates for highest_imputation = Y works", { # nolint +## Test 25: Supplying both min/max dates for highest_imputation = Y works ---- +test_that("derive_vars_dt Test 25: Supplying both min/max dates for highest_imputation = Y works", { # nolint actual <- data.frame( AESTDTC = c(NA_character_, NA_character_), TRTSDT = c(ymd("2022-01-01"), NA),