diff --git a/tests/testthat/test-derive_seq.R b/tests/testthat/test-derive_seq.R index b70398d6..b0aa578c 100644 --- a/tests/testthat/test-derive_seq.R +++ b/tests/testthat/test-derive_seq.R @@ -9,9 +9,9 @@ test_that("`derive_seq()` works as expected", { expected_vsseq <- tibble::tribble( ~STUDYID, ~DOMAIN, ~USUBJID, ~VSSPID, ~VSTESTCD, ~VSDTC, ~VSTPTNUM, ~VSSEQ, "ABC123", "VS", "ABC123-375", "/F:VTLS1-D:9795532-R:2", "DIABP", "2020-09-01T13:31", NA, 1L, - "ABC123", "VS", "ABC123-375", "/F:VTLS2-D:9795533-R:2", "DIABP", "2020-09-28T11:00", 2L, 2L, + "ABC123", "VS", "ABC123-375", "/F:VTLS2-D:9795533-R:2", "DIABP", "2020-09-28T11:00", 2, 2L, "ABC123", "VS", "ABC123-375", "/F:VTLS1-D:9795532-R:2", "TEMP", "2020-09-01T13:31", NA, 3L, - "ABC123", "VS", "ABC123-375", "/F:VTLS2-D:9795533-R:2", "TEMP", "2020-09-28T11:00", 2L, 4L, + "ABC123", "VS", "ABC123-375", "/F:VTLS2-D:9795533-R:2", "TEMP", "2020-09-28T11:00", 2, 4L, "ABC123", "VS", "ABC123-376", "/F:VTLS1-D:9795591-R:1", "DIABP", "2020-09-20", NA, 1L, "ABC123", "VS", "ABC123-376", "/F:VTLS1-D:9795591-R:1", "TEMP", "2020-09-20", NA, 2L ) @@ -48,5 +48,4 @@ test_that("`is_seq_name()`: basic usage", { expect_false(is_seq_name("AEseq")) expect_false(is_seq_name("AESEQUENCE")) - }) diff --git a/tests/testthat/test-dtc_parse_dttm.R b/tests/testthat/test-dtc_parse_dttm.R index 06416d5e..fa10d484 100644 --- a/tests/testthat/test-dtc_parse_dttm.R +++ b/tests/testthat/test-dtc_parse_dttm.R @@ -1,5 +1,4 @@ test_that("`parse_dttm()` works as expected", { - # Year expected_y <- tibble::tribble( ~year, ~mon, ~mday, ~hour, ~min, ~sec, @@ -7,8 +6,10 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm("2020", "y"), - expected_y) + expect_identical( + parse_dttm("2020", "y"), + expected_y + ) # Year, Month expected_ym <- tibble::tribble( @@ -17,8 +18,10 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm("2020-05", "y-m"), - expected_ym) + expect_identical( + parse_dttm("2020-05", "y-m"), + expected_ym + ) # Year, Month, Day expected_ymd <- tibble::tribble( @@ -27,8 +30,10 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm("2020-05-11", "y-m-d"), - expected_ymd) + expect_identical( + parse_dttm("2020-05-11", "y-m-d"), + expected_ymd + ) # Year, Month, Day in other formats parse_dttm("2020 05 11", "y m d") |> expect_identical(expected_ymd) @@ -38,50 +43,58 @@ test_that("`parse_dttm()` works as expected", { # Year, Month, Day, Hour, Minute expected_ymdhm <- tibble::tribble( ~year, ~mon, ~mday, ~hour, ~min, ~sec, - "2020", "05", "11", "11", "45", NA + "2020", "05", "11", "11", "45", NA ) |> as.matrix() - expect_identical(parse_dttm("2020-05-11 11:45", "y-m-d H:M"), - expected_ymdhm) + expect_identical( + parse_dttm("2020-05-11 11:45", "y-m-d H:M"), + expected_ymdhm + ) # Year, Month, Day, Hour, Minute, Second expected_ymdhms <- tibble::tribble( - ~year, ~mon, ~mday, ~hour, ~min, ~sec, - "2020", "05", "11", "11", "45", "15.6" + ~year, ~mon, ~mday, ~hour, ~min, ~sec, + "2020", "05", "11", "11", "45", "15.6" ) |> as.matrix() - expect_identical(parse_dttm("2020-05-11 11:45:15.6", "y-m-d H:M:S"), - expected_ymdhms) + expect_identical( + parse_dttm("2020-05-11 11:45:15.6", "y-m-d H:M:S"), + expected_ymdhms + ) # Multiple records expected_ymdhm_1 <- tibble::tribble( - ~year, ~mon, ~mday, ~hour, ~min, ~sec, - "2002", "05", "11", "11", "45", NA, - NA, NA, NA, NA, NA, NA + ~year, ~mon, ~mday, ~hour, ~min, ~sec, + "2002", "05", "11", "11", "45", NA, + NA, NA, NA, NA, NA, NA ) |> as.matrix() - expect_identical(parse_dttm(c("2002-05-11 11:45", "-05-11 11:45"), "y-m-d H:M"), - expected_ymdhm_1) + expect_identical( + parse_dttm(c("2002-05-11 11:45", "-05-11 11:45"), "y-m-d H:M"), + expected_ymdhm_1 + ) expected_ymdhm_2 <- tibble::tribble( ~year, ~mon, ~mday, ~hour, ~min, ~sec, - NA, NA, NA, NA, NA, NA, - NA, "05", "11", "11", "45", NA + NA, NA, NA, NA, NA, NA, + NA, "05", "11", "11", "45", NA ) |> as.matrix() - expect_identical(parse_dttm(c("2002-05-11 11:45", "-05-11 11:45"), "-m-d H:M"), - expected_ymdhm_2) + expect_identical( + parse_dttm(c("2002-05-11 11:45", "-05-11 11:45"), "-m-d H:M"), + expected_ymdhm_2 + ) expected_ymdhm_3 <- tibble::tribble( - ~year, ~mon, ~mday, ~hour, ~min, ~sec, - "2002", "05", "11", "11", "45", NA, - NA, "05", "11", "11", "45", NA + ~year, ~mon, ~mday, ~hour, ~min, ~sec, + "2002", "05", "11", "11", "45", NA, + NA, "05", "11", "11", "45", NA ) |> as.matrix() @@ -97,11 +110,15 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm("05 feb 1985 12 55 02", "d m y H M S"), - expected_ymdhm_4) + expect_identical( + parse_dttm("05 feb 1985 12 55 02", "d m y H M S"), + expected_ymdhm_4 + ) - expect_identical(parse_dttm("12 55 02 05 feb 1985", "H M S d m y"), - expected_ymdhm_4) + expect_identical( + parse_dttm("12 55 02 05 feb 1985", "H M S d m y"), + expected_ymdhm_4 + ) # UNK included expected_unk <- tibble::tribble( @@ -112,8 +129,10 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), "y-m-d"), - expected_unk) + expect_identical( + parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), "y-m-d"), + expected_unk + ) expected_unk_1 <- tibble::tribble( ~year, ~mon, ~mday, ~hour, ~min, ~sec, "2020", "05", "18", NA, NA, NA, @@ -122,10 +141,13 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), - "y-m-d", - na = "UN"), - expected_unk_1) + expect_identical( + parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), + "y-m-d", + na = "UN" + ), + expected_unk_1 + ) expected_unk_2 <- tibble::tribble( ~year, ~mon, ~mday, ~hour, ~min, ~sec, @@ -135,8 +157,11 @@ test_that("`parse_dttm()` works as expected", { ) |> as.matrix() - expect_identical(parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), - "y-m-d", - na = c("UN", "UNK")), - expected_unk_2) + expect_identical( + parse_dttm(c("2020-05-18", "2020-UN-18", "2020-UNK-UN"), + "y-m-d", + na = c("UN", "UNK") + ), + expected_unk_2 + ) }) diff --git a/tests/testthat/test-dtc_problems.R b/tests/testthat/test-dtc_problems.R index 4529629a..eefe6b77 100644 --- a/tests/testthat/test-dtc_problems.R +++ b/tests/testthat/test-dtc_problems.R @@ -24,6 +24,8 @@ test_that("`any_problems()`: basic usage", { cap_matrix_time <- parse_dttm(time, "H:M:S") cap_matrices <- list(cap_matrix_date, cap_matrix_time) - expect_identical(any_problems(cap_matrices), - c(TRUE, TRUE, FALSE, FALSE)) + expect_identical( + any_problems(cap_matrices), + c(TRUE, TRUE, FALSE, FALSE) + ) }) diff --git a/tests/testthat/test-dtc_utils.R b/tests/testthat/test-dtc_utils.R index 683e5a2f..b9c6bb56 100644 --- a/tests/testthat/test-dtc_utils.R +++ b/tests/testthat/test-dtc_utils.R @@ -1,25 +1,25 @@ test_that("`assert_dtc_fmt()`: basic usage", { - fmt <- c("ymd", "y m d", "dmy", "HM", "H:M:S", "y-m-d H:M:S") - expect_identical(assert_dtc_fmt(fmt), - fmt) + expect_identical( + assert_dtc_fmt(fmt), + fmt + ) expect_error(assert_dtc_fmt("y years m months d days")) }) test_that("`assert_dtc_format()`: basic usage", { - expect_identical(assert_dtc_format("ymd"), "ymd") expect_identical(assert_dtc_format(c("ymd", "y-m-d")), c("ymd", "y-m-d")) - expect_identical(assert_dtc_format(list(c("ymd", "y-m-d"), "H:M:S")), - list(c("ymd", "y-m-d"), "H:M:S")) + expect_identical( + assert_dtc_format(list(c("ymd", "y-m-d"), "H:M:S")), + list(c("ymd", "y-m-d"), "H:M:S") + ) expect_error(assert_dtc_format("year, month, day")) - }) test_that("`assert_capture_matrix()`: basic usage", { - cols <- c("year", "mon", "mday", "hour", "min", "sec") m <- matrix(NA_character_, nrow = 1L, ncol = 6L, dimnames = list(NULL, cols)) expect_identical(assert_capture_matrix(m), m) @@ -30,7 +30,6 @@ test_that("`assert_capture_matrix()`: basic usage", { }) test_that("`complete_capture_matrix()`: basic usage", { - # Input with no cols and rows input <- matrix(data = NA_character_, nrow = 0L, ncol = 0L) expected_output <- matrix( @@ -40,8 +39,10 @@ test_that("`complete_capture_matrix()`: basic usage", { dimnames = list(NULL, c("year", "mon", "mday", "hour", "min", "sec")) ) - expect_identical(complete_capture_matrix(input), - expected_output) + expect_identical( + complete_capture_matrix(input), + expected_output + ) # Input with no cols and 1 row input <- matrix(data = NA_character_, nrow = 1L) @@ -52,8 +53,10 @@ test_that("`complete_capture_matrix()`: basic usage", { dimnames = list(NULL, c("year", "mon", "mday", "hour", "min", "sec")) ) - expect_identical(complete_capture_matrix(input), - expected_output) + expect_identical( + complete_capture_matrix(input), + expected_output + ) # Input with incomplete cols input <- @@ -71,8 +74,10 @@ test_that("`complete_capture_matrix()`: basic usage", { dimnames = list(NULL, c("year", "mon", "mday", "hour", "min", "sec")) ) - expect_identical(complete_capture_matrix(input), - expected_output) + expect_identical( + complete_capture_matrix(input), + expected_output + ) # Input with year and second specified input <- @@ -91,8 +96,10 @@ test_that("`complete_capture_matrix()`: basic usage", { dimnames = list(NULL, c("year", "mon", "mday", "hour", "min", "sec")) ) - expect_identical(complete_capture_matrix(input), - expected_output) + expect_identical( + complete_capture_matrix(input), + expected_output + ) # Any other existing columns are dropped. input <- @@ -110,12 +117,13 @@ test_that("`complete_capture_matrix()`: basic usage", { dimnames = list(NULL, c("year", "mon", "mday", "hour", "min", "sec")) ) - expect_identical(complete_capture_matrix(input), - expected_output) + expect_identical( + complete_capture_matrix(input), + expected_output + ) }) test_that("`coalesce_capture_matrices()`: basic usage", { - cols <- c("year", "mon", "mday", "hour", "min", "sec") dates <- c("2020", "01", "01", "20", NA, NA) times <- c(NA, NA, NA, "10", "00", "05") diff --git a/tests/testthat/test-iso8601.R b/tests/testthat/test-iso8601.R index f90619b0..c32114a4 100644 --- a/tests/testthat/test-iso8601.R +++ b/tests/testthat/test-iso8601.R @@ -44,7 +44,6 @@ test_that("`iso8601_two_digits()`: basic usage", { }) test_that("`iso8601_year()`: basic usage", { - expect_identical( iso8601_year(c("0", "1", "2", "50", "68", "69", "90", "99", "00")), c("2000", "2001", "2002", "2050", "2068", "1969", "1990", "1999", "2000") @@ -62,16 +61,18 @@ test_that("`iso8601_year()`: basic usage", { ) # Set cutoff_2000 to something else - expect_identical(iso8601_year(as.character(0L:50L), cutoff_2000 = 25L), - as.character(c(2000L:2025L, 1926L:1950L))) - - expect_identical(iso8601_year(as.character(1900L:1950L), cutoff_2000 = 25L), - as.character(c(1900L:1950L))) + expect_identical( + iso8601_year(as.character(0L:50L), cutoff_2000 = 25L), + as.character(c(2000L:2025L, 1926L:1950L)) + ) + expect_identical( + iso8601_year(as.character(1900L:1950L), cutoff_2000 = 25L), + as.character(c(1900L:1950L)) + ) }) test_that("`iso8601_mon()`: basic usage", { - expect_identical( iso8601_mon(c(NA, "0", "1", "2", "10", "11", "12")), c(NA, "00", "01", "02", "10", "11", "12") @@ -86,13 +87,13 @@ test_that("`iso8601_mon()`: basic usage", { ) mon <- month.abb - expect_identical(iso8601_mon(mon), - c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")) - + expect_identical( + iso8601_mon(mon), + c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12") + ) }) test_that("`iso8601_sec()`: basic usage", { - expect_identical( iso8601_sec(c(NA, "0", "1", "10", "59", "99", "100")), c(NA, "00", "01", "10", "59", "99", NA) @@ -100,7 +101,6 @@ test_that("`iso8601_sec()`: basic usage", { }) test_that("`iso8601_truncate()`: basic usage", { - x <- c( "1999-01-01T15:20:01", @@ -114,8 +114,10 @@ test_that("`iso8601_truncate()`: basic usage", { expect_identical( iso8601_truncate(x), - c("1999-01-01T15:20:01", "1999-01-01T15:20", "1999-01-01T15", "1999-01-01", - "1999-01", "1999", NA) + c( + "1999-01-01T15:20:01", "1999-01-01T15:20", "1999-01-01T15", "1999-01-01", + "1999-01", "1999", NA + ) ) # With `empty_as_na = FALSE` empty strings are not replaced with `NA` @@ -140,5 +142,4 @@ test_that("`iso8601_truncate()`: basic usage", { "1999-01-01" ) ) - }) diff --git a/tests/testthat/test-oak_id_vars.R b/tests/testthat/test-oak_id_vars.R index 7c64f257..c16d5ef3 100644 --- a/tests/testthat/test-oak_id_vars.R +++ b/tests/testthat/test-oak_id_vars.R @@ -1,9 +1,13 @@ test_that("`oak_id_vars`: basic usage", { - expect_identical(oak_id_vars(), - c("oak_id", "raw_source", "patient_number")) + expect_identical( + oak_id_vars(), + c("oak_id", "raw_source", "patient_number") + ) - expect_identical(oak_id_vars(extra_vars = "sample_id"), - c("oak_id", "raw_source", "patient_number", "sample_id")) + expect_identical( + oak_id_vars(extra_vars = "sample_id"), + c("oak_id", "raw_source", "patient_number", "sample_id") + ) }) test_that("`contains_oak_id_vars()`: basic usage", { diff --git a/tests/testthat/test-parse_dttm_fmt.R b/tests/testthat/test-parse_dttm_fmt.R index cfbc440f..13e951df 100644 --- a/tests/testthat/test-parse_dttm_fmt.R +++ b/tests/testthat/test-parse_dttm_fmt.R @@ -207,21 +207,30 @@ test_that("`fmt_rg`: basic usage", { }) test_that("`dttm_fmt_to_regex`: basic usage", { + expect_identical( + dttm_fmt_to_regex("y"), + "^(?(\\d{2})?\\d{2})$" + ) - expect_identical(dttm_fmt_to_regex("y"), - "^(?(\\d{2})?\\d{2})$") - - expect_identical(dttm_fmt_to_regex("y", anchored = FALSE), - "(?(\\d{2})?\\d{2})") + expect_identical( + dttm_fmt_to_regex("y", anchored = FALSE), + "(?(\\d{2})?\\d{2})" + ) # nolint start - expect_identical(dttm_fmt_to_regex("m"), - "^(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])$") + expect_identical( + dttm_fmt_to_regex("m"), + "^(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])$" + ) - expect_identical(dttm_fmt_to_regex("ymd"), - "^(?(\\d{2})?\\d{2})(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])(?\\b\\d|\\d{2})$") + expect_identical( + dttm_fmt_to_regex("ymd"), + "^(?(\\d{2})?\\d{2})(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])(?\\b\\d|\\d{2})$" + ) - expect_identical(dttm_fmt_to_regex("ymd HH:MM:SS"), - "^(?(\\d{2})?\\d{2})(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])(?\\b\\d|\\d{2}) (?\\d?\\d):(?(\\b\\d|\\d{2})):(?(\\b\\d|\\d{2})(\\.\\d*)?)$") + expect_identical( + dttm_fmt_to_regex("ymd HH:MM:SS"), + "^(?(\\d{2})?\\d{2})(?\\d\\d|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])(?\\b\\d|\\d{2}) (?\\d?\\d):(?(\\b\\d|\\d{2})):(?(\\b\\d|\\d{2})(\\.\\d*)?)$" + ) # nolint end }) @@ -230,8 +239,10 @@ test_that("`regrex_or`: basic usage", { # Setting `.open` and/or `.close` to `TRUE` can be handy if this regex # is to be combined into a larger regex. - expect_identical(paste0(regex_or(c("jan", "feb"), .close = TRUE), r"{\d{2}}"), - "jan|feb|\\d{2}") + expect_identical( + paste0(regex_or(c("jan", "feb"), .close = TRUE), r"{\d{2}}"), + "jan|feb|\\d{2}" + ) }) test_that("`parse_dttm_fmt`: empty fmt", { @@ -309,10 +320,14 @@ test_that("`parse_dttm_fmt` works as expected", { expect_identical(observed_y, expected_y) # Specify custom patterns - observed_cus <- parse_dttm_fmt("year month day", - fmt_cmp(year = "year", - mon = "month", - mday = "day")) + observed_cus <- parse_dttm_fmt( + "year month day", + fmt_cmp( + year = "year", + mon = "month", + mday = "day" + ) + ) expected_cus <- tibble::tribble( ~fmt_c, ~pat, ~cap, ~start, ~end, ~len, ~ord, diff --git a/tests/testthat/test-recode.R b/tests/testthat/test-recode.R index c93f50a0..a100a1a7 100644 --- a/tests/testthat/test-recode.R +++ b/tests/testthat/test-recode.R @@ -125,7 +125,8 @@ test_that("recode(): notable cases", { }) test_that("index_for_recode(): basic usage", { - expect_identical(index_for_recode(x = 1L:5L, from = c(2L, 4L)), - as.integer(c(NA, 1L, NA, 2L, NA))) - + expect_identical( + index_for_recode(x = 1L:5L, from = c(2L, 4L)), + as.integer(c(NA, 1L, NA, 2L, NA)) + ) })