library(testthat)
data(lendclub)
# 1
test_that("getBadRate - standard case",{
data(lendclub)
toTest <- getBadRate(lendclub$loan_status, lendclub$home_ownership)
expect_equal(as.vector(toTest)[1], 0)
expect_equal(round(as.vector(toTest)[2],5), 0.11735)
expect_equal(round(as.vector(toTest)[3],5), 0.24)
expect_equal(round(as.vector(toTest)[4],5), 0.35714)
expect_equal(round(as.vector(toTest)[5],5), 0.13525)
expect_equal(round(as.vector(toTest)[6],5), 0.15454)
})
# 2
test_that("getBadRate - only defaults",{
y <- rep(TRUE, 10);
x <- as.factor(rep(letters[1:5],2))
toTest <- getBadRate(y, x)
expect_equal(sum(toTest), length(levels(x)))
})
# 3
test_that("getBadRate - only NA",{
y <- rep(NA, 10)
x <- as.factor(rep(letters[1:5],2))
toTest <- getBadRate(y, x)
expect_equal(all(is.na(toTest)), TRUE)
})
# 4
test_that("getBadRate - bad yVar",{
y <- runif(10)
x <- as.factor(rep(letters[1:5],2))
expect_error(getBadRate(y, x), "yVar must be logical")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.