library(testthat)
data(lendclub)
# 0
test_that("getIV - standard case",{
toTest <- getIV(yVar = lendclub$loan_status, lendclub$home_ownership)
expect_equal(sum(toTest[,"iv"]), 0.02326146)
expect_equal(sum(toTest[,"sBad"]), 1)
expect_equal(sum(toTest[,"sGood"]), 1)
})
# 1
test_that("getIV - random case",{
y <- runif(10) < 0.5
x <- as.factor(sample(letters[1:4], size = 10, replace = T))
toTest <- getIV(y, x)
expect_equal(sum(toTest[,"sBad"]), 1)
expect_equal(sum(toTest[,"sGood"]), 1)
})
# 2
test_that("getIV - only defaults",{
y <- rep(TRUE, 10);
x <- as.factor(rep(letters[1:5],2))
expect_error(getIV(y, x), "yVar is constant")
})
# 3
test_that("getIV - 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("getIV - 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.