mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2025-09-12 02:29:39 +02:00
new tests
This commit is contained in:
parent
2aa268f747
commit
9390735af3
2 changed files with 58 additions and 1 deletions
56
tests/testthat/test-as_factor.R
Normal file
56
tests/testthat/test-as_factor.R
Normal file
|
@ -0,0 +1,56 @@
|
|||
# library(testthat)
|
||||
test_that("fct2num works", {
|
||||
expect_equal(2 * 2, 4)
|
||||
|
||||
expect_equal(
|
||||
c(1, 4, 3, "A", 7, 8, 1) |>
|
||||
as_factor() |> # named_levels()
|
||||
fct2num(),
|
||||
c(1, 2, 3, 4, 5, 6, 1)
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10),
|
||||
class = "haven_labelled"
|
||||
) |>
|
||||
as_factor() |>
|
||||
fct2num(),
|
||||
c(1, 2, 3, 2, 10, 9)
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10),
|
||||
class = "labelled"
|
||||
) |>
|
||||
as_factor() |>
|
||||
fct2num(),
|
||||
c(1, 2, 3, 2, 10, 9)
|
||||
)
|
||||
|
||||
|
||||
expect_equal(
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10)
|
||||
) |>
|
||||
as_factor.labelled() |>
|
||||
fct2num(),
|
||||
c(1, 2, 3, 2, 10, 9)
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
structure(c(1, 2, 3, 2, 10, 9),
|
||||
labels = c(Unknown = 9, Refused = 10),
|
||||
class = "labelled"
|
||||
) |>
|
||||
as_factor() |> dput(),
|
||||
structure(c(1L, 2L, 3L, 2L, 5L, 4L), levels = c(
|
||||
"1", "2", "3",
|
||||
"Unknown", "Refused"
|
||||
), class = "factor", labels = c(
|
||||
Unknown = 9,
|
||||
Refused = 10
|
||||
))
|
||||
)
|
||||
})
|
|
@ -1,3 +1,4 @@
|
|||
library(testthat)
|
||||
test_that("redcap_wider() returns expected output", {
|
||||
list <-
|
||||
list(
|
||||
|
@ -15,7 +16,7 @@ test_that("redcap_wider() returns expected output", {
|
|||
|
||||
expect_equal(
|
||||
redcap_wider(list),
|
||||
data.frame(
|
||||
dplyr::tibble(
|
||||
record_id = c(1, 2),
|
||||
age_baseline = c(25, 26),
|
||||
age_followup = c(27, 28),
|
||||
|
|
Loading…
Add table
Reference in a new issue