# Test db context("DB Utilities - safe Cap") test_that("simpleCap has proper error for non-character data", { expect_error(simpleCap(2)) expect_error(simpleCap(TRUE)) expect_error(simpleCap(factor("cat"))) }) test_that("simpleCap capitalizes characters", { expect_equal(simpleCap("my car"), "My Car") expect_equal(simpleCap("car"), "Car") expect_equal(simpleCap("car_2"), "Car_2") }) context("DB Utilities - Count NA") test_that("countNA works on character vectors", { expect_equal(countNA(c("A", "B", NA, "C")), 1) expect_equal(countNA(rep(NA_character_, 100)), 100) expect_equal(countNA(c("car", "dog", "house", NA, NA, NA, NA)), 4) }) test_that("countNA returns 0 when no NAs are found", { expect_equal(countNA(rnorm(100)), 0) expect_equal(countNA(LETTERS), 0) expect_equal(countNA(state.abb), 0) }) context("DB Utilities - nvals") test_that("nvals works for character values", { expect_equal(nvals(LETTERS), 26) expect_equal(nvals(state.abb), 50) }) test_that("nvals works with missing values", { expect_equal(nvals(c(letters, NA)), 27) expect_equal(nvals(c(letters, NA, NA)), 27) expect_equal(nvals(rep(NA, 100)), 1) }) context("DB Utilities - dbSafeNames") test_that("dbsafenames does not change all lowercase", { char <- "alligator" expect_equal(dbSafeNames(char), char) char <- "hotdog" expect_equal(dbSafeNames(char), char) }) test_that("dbsafenames replaces spaces", { char_old <- "hot dog" char_new <- "hot_dog" expect_equal(dbSafeNames(char_old), char_new) char_old <- "alligator cat" char_new <- "alligator_cat" expect_equal(dbSafeNames(char_old), char_new) }) test_that("dbsafenames replaces periods", { char_old <- "hot.dog" char_new <- "hot_dog" expect_equal(dbSafeNames(char_old), char_new) char_old <- "alligator.cat" char_new <- "alligator_cat" expect_equal(dbSafeNames(char_old), char_new) }) test_that("dbsafenames replaces forces nocaps", { char_old <- "HoTDoG" char_new <- "hotdog" expect_equal(dbSafeNames(char_old), char_new) char_old <- "AlLiGaTorCaT" char_new <- "alligatorcat" expect_equal(dbSafeNames(char_old), char_new) })