install logo correctly
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
# 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)
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
# context("Histograms")
|
||||
#
|
||||
# library(ggplot2)
|
||||
# disp_hist_base <- function() hist(mtcars$disp)
|
||||
# disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram()
|
||||
#
|
||||
# test_that({
|
||||
# skip("Not currently working")
|
||||
# vdiffr::expect_doppelganger("Base graphics histogram", disp_hist_base)
|
||||
# vdiffr::expect_doppelganger("ggplot2 histogram", disp_hist_ggplot)
|
||||
#
|
||||
# })
|
||||
@@ -0,0 +1,53 @@
|
||||
# Test utils
|
||||
|
||||
context("Test Utilities - Safe Max")
|
||||
test_that("safe_max excludes NAs", {
|
||||
samp_a <- c(1:10, NA)
|
||||
expect_equal(safe_max(samp_a), 10)
|
||||
expect_equal(safe_max(samp_a), max(samp_a, na.rm = TRUE))
|
||||
expect_equal(safe_max(c("cat", "box", "dog")), "dog")
|
||||
expect_equal(safe_max(c("cat", "box", "dog")), max(c("cat", "box", "dog"), na.rm = TRUE))
|
||||
|
||||
})
|
||||
|
||||
test_that("safe_max handles all NAs", {
|
||||
expect_equal(safe_max(rep(NA, 100)), NA)
|
||||
expect_equal(safe_max(NULL), NA)
|
||||
|
||||
})
|
||||
|
||||
context("Test Utilities - Pretty Per")
|
||||
|
||||
test_that("pretty_per respects rounding", {
|
||||
expect_identical(pretty_per(0.2), "20.0%")
|
||||
expect_identical(pretty_per(0.2432522), "24.3%")
|
||||
expect_identical(pretty_per(0.2432522, ndigit = 3), "24.325%")
|
||||
})
|
||||
|
||||
|
||||
test_that("pretty_per handles NAs", {
|
||||
expect_equivalent(pretty_per(rep(NA, 5)), c("-", "-", "-", "-", "-"))
|
||||
|
||||
})
|
||||
|
||||
test_that("pretty_per deals with large numbers", {
|
||||
expect_message(pretty_per(c(0.2, 0.5, 0.1, 110)))
|
||||
|
||||
})
|
||||
|
||||
context("Test Utilities - NA Zero")
|
||||
|
||||
test_that("Function works when no NAs present", {
|
||||
expect_equivalent(na_zero(1:10), 1:10)
|
||||
expect_equivalent(na_zero(letters), letters)
|
||||
|
||||
})
|
||||
|
||||
test_that("Function subs out NAs in numeric vectors with 0", {
|
||||
expect_equivalent(na_zero(c(1:10, NA)), c(1:10, 0))
|
||||
})
|
||||
|
||||
context("Test Utilities - Pretty Count")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user