tests/testthat/test-candles.R

context("Candelstick plot")

load_data <- function() {
  h <- new.env()
  load("testdata/history.RData",envir=h)
  return(get("history",envir=h))
}

test_that("requires clean columns",{
  h <- load_data()
  XLE <- get("XLE",envir=h)
  expect_error(gg_candles(get("XLE")))
})

test_that("accepts defaults", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  colnames(XLE) <- gsub("XLE.","",colnames(XLE))
  g <- gg_candles(XLE)
  expect_equal(length(g),10)
  expect_equal(ncol(g$data),9)
  expect_equal(length(g$layers),3)
  expect_equal(length(g$mapping),1)
  expect_equal(length(g$theme),57)
})

test_that("accepts title", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  test_title <- "XLE Adjusted"
  colnames(XLE) <- gsub("XLE.","",colnames(XLE))
  g <- gg_candles(XLE,title_param=test_title)
  expect_equal(length(g),10)
  expect_equal(ncol(g$data),9)
  expect_equal(length(g$layers),3)
  expect_equal(length(g$mapping),1)
  expect_equal(length(g$theme),57)
  expect_equal(g$labels$title,test_title)
})
greatgray/scorecard documentation built on May 17, 2019, 8:34 a.m.