# This file covers the code in Table1.R. View coverage for this file using
test_that("createTable1 works with categorical covariates", {
skip_if_not(dbms == "sqlite" && exists("eunomiaConnection"))
expect_error(createTable1("blah"), "not of type 'covariateData'")
expect_error(createTable1(covariateData1, output = "blah"), "The `output` argument  must be")
expect_error(createTable1(covariateData1, showCounts = F, showPercent = F), "counts or percent")
table1 <- createTable1(covariateData1, specifications = getDefaultTable1Specifications()[1:2, ])
expect_equal(names(table1)[2], "% (n = 638)")
table1 <- createTable1(covariateData1, output = "one column")
expect_equal(names(table1), c("Characteristic", "% (n = 638)"))
expect_error(createTable1(covariateData1, "blah"), "not of type 'covariateData'")
table1 <- createTable1(covariateData1, covariateData2, output = "one column")
expect_equal(names(table1), c("Characteristic", "% (n = 638)", "% (n = 252)", "Std.Diff"))
expect_error(createTable1(rawCovariateData), "data is not aggregated")
expect_error(createTable1(covariateData1, rawCovariateData), "data is not aggregated")
test_that("createTable1 works with continuous covariates", {
settings <- createCovariateSettings(useChads2Vasc = TRUE)
table1 <- createTable1(covariateData3, output = "one column", showCounts = T, showPercent = T)
test_that("createTable1 works with other covariates", {
spec <- spec[which(spec$label %in% c("CHADS2Vasc", "Age group")), ]
table1 <- createTable1(covariateData1, specifications = spec, output = "list")

"createTable1 works with categorical covariates"
"createTable1 works with continuous covariates"
"createTable1 works with other covariates"

createTable1 works with categorical covariates

names(table1) not equal to c("Characteristic", "% (n = 638)").
1/2 mismatches
x[2]: "% (n = 1,844)"
y[2]: "% (n = 638)"