mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2026-06-19 04:27:30 +02:00
data type icons in summary - more tests
This commit is contained in:
parent
652a8ca1b7
commit
50d35c0c85
15 changed files with 406 additions and 2493 deletions
|
|
@ -8,5 +8,6 @@
|
|||
|
||||
library(testthat)
|
||||
library(FreesearchR)
|
||||
library(shiny)
|
||||
|
||||
test_check("FreesearchR")
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3,44 +3,26 @@
|
|||
|
||||
test_that("Creates correct table",{
|
||||
## This is by far the easiest way to test all functions. Based on examples.
|
||||
expect_snapshot(create_baseline(mtcars,by.var = "gear", add.p = "yes" == "yes",add.overall = TRUE, theme = "lancet"))
|
||||
expect_snapshot(create_baseline(mtcars,by.var = "none", add.p = FALSE,add.overall = FALSE, theme = "lancet"))
|
||||
expect_snapshot(create_baseline(mtcars,by.var = "test", add.p = FALSE,add.overall = FALSE, theme = "jama"))
|
||||
expect_snapshot(create_baseline(default_parsing(mtcars),by.var = "am", add.p = FALSE,add.overall = FALSE, theme = "nejm"))
|
||||
})
|
||||
tbl <- create_baseline(mtcars,by.var = "gear", add.p = "yes" == "yes",add.overall = TRUE, theme = "lancet")
|
||||
|
||||
test_that("Creates table", {
|
||||
tbl <- mtcars |> baseline_table(fun.args = list(by = "gear"))
|
||||
|
||||
expect_equal(length(tbl), 5)
|
||||
|
||||
expect_equal(NROW(tbl$table_body), 19)
|
||||
|
||||
expect_equal(NCOL(tbl$table_body), 8)
|
||||
|
||||
expect_equal(names(tbl), c("table_body", "table_styling", "call_list", "cards", "inputs"))
|
||||
})
|
||||
|
||||
test_that("Creates table", {
|
||||
tbl <- mtcars |> create_baseline(by.var = "gear", add.p = "yes" == "yes")
|
||||
|
||||
expect_equal(length(tbl), 5)
|
||||
expect_equal(length(tbl),5)
|
||||
|
||||
expect_equal(NROW(tbl$table_body), 19)
|
||||
|
||||
expect_equal(NCOL(tbl$table_body), 13)
|
||||
|
||||
tbl$call_list
|
||||
expect_equal(names(tbl), c("table_body", "table_styling", "call_list", "cards", "inputs"))
|
||||
|
||||
tbl <- create_baseline(mtcars,by.var = "none", add.p = FALSE,add.overall = FALSE, theme = "lancet")
|
||||
|
||||
expect_equal(length(tbl),5)
|
||||
|
||||
tbl <- create_baseline(mtcars,by.var = "test", add.p = FALSE,add.overall = FALSE, theme = "jama")
|
||||
|
||||
expect_equal(length(tbl),5)
|
||||
|
||||
tbl <- create_baseline(default_parsing(mtcars),by.var = "am", add.p = FALSE,add.overall = FALSE, theme = "nejm")
|
||||
|
||||
expect_equal(length(tbl),5)
|
||||
})
|
||||
|
||||
test_that("Creates table", {
|
||||
tbl <- mtcars |> create_baseline(by.var = "gear", add.p = "yes" == "yes")
|
||||
|
||||
expect_equal(length(tbl), 5)
|
||||
|
||||
expect_equal(NROW(tbl$table_body), 19)
|
||||
|
||||
expect_equal(NCOL(tbl$table_body), 13)
|
||||
|
||||
expect_equal(names(tbl), c("table_body", "table_styling", "call_list", "cards", "inputs"))
|
||||
})
|
||||
|
|
|
|||
47
tests/testthat/test-cut-variable-dates.R
Normal file
47
tests/testthat/test-cut-variable-dates.R
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
test_that("datetime cutting works", {
|
||||
## HMS
|
||||
data <- readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20"))
|
||||
|
||||
breaks <- list(2, "min", "hour", hms::as_hms(c("01:00:00", "03:01:20", "9:20:20")))
|
||||
|
||||
lapply(breaks, \(.x){
|
||||
cut_var(x = data, breaks = .x)
|
||||
}) |> expect_snapshot()
|
||||
|
||||
|
||||
data <- readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "03:02:20", NA))
|
||||
|
||||
lapply(breaks, \(.x){
|
||||
cut_var(x = data, breaks = .x)
|
||||
}) |> expect_snapshot()
|
||||
|
||||
expect_snapshot(
|
||||
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "03:02:20", NA)) |> cut_var(breaks = lubridate::as_datetime(c(hms::as_hms(levels(cut_var(data, 2))), hms::as_hms(max(data, na.rm = TRUE) + 1))), right = FALSE)
|
||||
)
|
||||
|
||||
## DATETIME
|
||||
|
||||
data <- readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20"))
|
||||
|
||||
breaks <- list(list(breaks = 2), list(breaks = "weekday"), list(breaks = "month_only"), list(breaks = NULL, format = "%A-%H"))
|
||||
|
||||
lapply(breaks, \(.x){
|
||||
do.call(cut_var, modifyList(.x, list(x = data)))
|
||||
}) |> expect_snapshot()
|
||||
})
|
||||
|
||||
## is_any_class
|
||||
test_that("is_any_class works", {
|
||||
expect_snapshot(
|
||||
vapply(REDCapCAST::redcapcast_data, \(.x){
|
||||
is_any_class(.x, c("hms", "Date", "POSIXct", "POSIXt"))
|
||||
}, logical(1))
|
||||
)
|
||||
|
||||
expect_snapshot(
|
||||
vapply(REDCapCAST::redcapcast_data, is_datetime, logical(1))
|
||||
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
|
|
@ -41,7 +41,6 @@ test_that("get_plot_options works", {
|
|||
|
||||
## create_plot and friends
|
||||
test_that("create_plot works", {
|
||||
|
||||
## Violin
|
||||
p_list <- create_plot(mtcars, type = "plot_violin", pri = "mpg", sec = "cyl", ter = "am")
|
||||
p <- p_list[[1]] + ggplot2::labs(title = "Test plot")
|
||||
|
|
@ -81,6 +80,6 @@ test_that("get_label works", {
|
|||
## line_break
|
||||
test_that("line_break works", {
|
||||
expect_snapshot("Lorem ipsum... you know the routine" |> line_break())
|
||||
expect_snapshot(paste(sample(letters[1:10], 100, TRUE), collapse = "") |> line_break(force = TRUE, lineLength = 5))
|
||||
expect_snapshot(paste(sample(letters[1:10], 100, TRUE), collapse = "") |> line_break(force = FALSE))
|
||||
expect_snapshot(paste(rep(letters, 5), collapse = "") |> line_break(force = TRUE, lineLength = 5))
|
||||
expect_snapshot(paste(rep(letters, 5), collapse = "") |> line_break(force = FALSE))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue