tests/2.R

#'Test Case for createCustomTimeSeries
#'@import RUnit, xts

library(RUnit)
library(xts)
test.createCustomTimeSeries <- function() {
  values <- c(1,2,3,4,5)
  intervals <- c(60,60,30,60)
  intervalsTooShort <- c(60, 60, 30)
  intervalsTooLong <- c(60, 60, 30, 60, 60)

  tsNoIntervals <- createCustomTimeSeries(values = values)
  tsIntervals <- createCustomTimeSeries(values = values, intervals = intervals)

  checkTrue(is.xts(tsIntervals), msg = "Did not create an xts object")
  checkTrue(is.xts(tsNoIntervals), msg = "Did not create an xts object")

  checkException(
    tsShortIntervals <- createCustomTimeSeries(values = values, intervals = intervalsTooShort),
    msg = "Should throw exception when length(intervals) is less than length(values)-1"
  )
  checkException(
    tsLongIntervals <- createCustomTimeSeries(values = values, intervals = intervalsTooLong),
    msg = "Should throw exception when length(intervals) is greater than length(values)-1"

  )

  checkEquals(
    time(tsIntervals[1]), time(tsIntervals[2])-60,
              "The intervals were not set correctly.")
  checkEquals(
    time(tsIntervals[2]), time(tsIntervals[3])-60,
              "The intervals were not set correctly.")
  checkEquals(
    time(tsIntervals[3]), time(tsIntervals[4])-30,
              "The intervals were not set correctly.")
  checkEquals(
    time(tsIntervals[4]), time(tsIntervals[5])-60,
    "The intervals were not set correctly.")

}
joshmarsh/TSTestDataUtil documentation built on May 19, 2019, 8:54 p.m.