tests/testthat/test-plot-stat.R

suppressPackageStartupMessages(require(quantmod))

context("Plot model stat")

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

test_that("accepts defaults", {
  h <- load_data()
  XLE <- get("XLE",envir=h)

  test_title <- "XLE Adjusted"
  g <- plot_model_stat(Ad(XLE),test_title)
  expect_equal(length(g),9)
  expect_equal(ncol(g$data),2)
  expect_equal(length(g$layers),1)
  expect_equal(length(g$mapping),2)
  expect_equal(length(g$theme),0)
  expect_equal(g$labels$title,test_title)
})

test_that("empty title fails", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  expect_error(plot_model_stat(Ad(XLE)))
})

test_that("change y label", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  new_y_label <- "Close ($)"
  g <- plot_model_stat(Cl(XLE),"Change Y",y_label=new_y_label)
  expect_equal(g$scales$scales[[1]]$name,new_y_label)
})

test_that("change line color", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  g <- plot_model_stat(Cl(XLE),"Change Color",line_color="black")
  expect_true("ggplot" %in% class(g))
  expect_equal(length(g),9)
  expect_equal(ncol(g$data),2)
})
greatgray/scorecard documentation built on May 17, 2019, 8:34 a.m.