tests/testthat/test-giniChart.R

context("giniChart")
library("ggplot2")
test_that("giniChart correctly produce a chart, numeric outcome", {
    rm(list = ls())
    sampledata <- data.frame(val = rnorm(100), outcome = rbinom(100, 1, 0.8))
    check1 <- ggplot_build(giniChart(sampledata$val, sampledata$outcome))
    expect(inherits(check1,c("ggplot_built","list")),"Not of expected class")
})

test_that("giniChart correctly produce a chart, factor outcome", {
    rm(list = ls())
    sampledata <- data.frame(val = rnorm(100), outcome = factor(rbinom(100, 1, 0.8)))
    check1 <- ggplot_build(giniChart(sampledata$val, sampledata$outcome))
    expect(inherits(check1,c("ggplot_built","list")),"Not of expected class")
})

test_that("giniChart errors given incorrect input to pred", {
    rm(list = ls())
    sampledata <- data.frame(val = rnorm(100), outcome = factor(rbinom(100, 1, 0.8)))
    expect_error(giniChart(sampledata$outcome, sampledata$val))
})

test_that("giniChart errors given continuous input to act", {
    rm(list = ls())
    sampledata <- data.frame(val = rnorm(100), outcome = factor(rbinom(100, 1, 0.8)))
    expect_error(giniChart(sampledata$val, sampledata$val))
})

test_that("giniChart warns given character input to act", {
    rm(list = ls())
    sampledata <- data.frame(val = rnorm(26), outcome = letters, stringsAsFactors = FALSE)
    expect_error(giniCoef(sampledata$val, sampledata$outcome))
}) 

Try the optiRum package in your browser

Any scripts or data that you put into this service are public.

optiRum documentation built on May 5, 2022, 1:05 a.m.