tests/testthat/test_for_risk_of_price_change.R

library(PawelKawskiPackage)
context("risk_of_price_change properties")

A <- risk_of_price_change("YHOO",100,0.05)

test_that("risk_of_price_change is data frame with 3 columns", {
  expect_equal(is.data.frame(A) & ncol(A) == 3, TRUE)
})

test_that(" Maximum value is greater then minimum value", {
  expect_equal( A[1,2] > A[1,3], TRUE)
})
test_that(" Maximum value and minimum value make sense, i.e. they are not too extreme", {
  expect_equal(A[1,2] < A[1,1]*10 & A[1,3] > A[1,1]*0.1, TRUE)
})
test_that(" Number of simulated days = 7/2 results in an error", {
  expect_error(risk_of_price_change("YHOO",3/2,0.05),"Number of days must be integer value and greater then 0")
})
test_that(" symbol which is not character value results in an error", {
  expect_error(risk_of_price_change(111,100,0.05,"open"),"symbol is not a character vector")
})
test_that(" price_type which is not set on \"close\" or \"open\" results in an error", {
  expect_error(risk_of_price_change("GOOG",100,0.05,"high"),"price_type == \"close\" | price_type == \"open\" is not TRUE")
})
mrepsilon/PawelKawskiPackage documentation built on May 21, 2019, 2:22 p.m.