context("Test getSliceDataSharadar")
# Test generic function
test_that("function returns correct data.", {
start.date <- as.Date("2018-10-29")
end.date <- as.Date("2018-10-30")
columns <- c("open", "high", "low", "close", "volume", "dividend",
"adj.open", "adj.high", "adj.low", "adj.close", "adj.volume")
# data <- getSliceDataSharadar(settings$sharadar.db, columns,
# start.date, end.date, FALSE)
data <- getSliceDataSharadar(settings$sharadar.sqli, columns,
start.date, end.date, FALSE)
# Check type and dim
expect_is(data, "list")
expect_equal(nrow(data$close), 2)
expect_gte(ncol(data$close), 5779)
# Check all list names
expect_equal(names(data), columns)
# Check all list contents are xts
for (i in 1:length(data)) expect_is(data[[i]], "xts")
# Check values of un-adjusted price
expect_equal(data$open[start.date, "AAPL"] %>% as.numeric(), 219.19)
expect_equal(data$high[start.date, "AAPL"] %>% as.numeric(), 219.69)
expect_equal(data$low[start.date, "AAPL"] %>% as.numeric(), 206.09)
expect_equal(data$close[start.date, "AAPL"] %>% as.numeric(), 212.24)
expect_equal(data$open[end.date, "AAPL"] %>% as.numeric(), 211.15)
expect_equal(data$high[end.date, "AAPL"] %>% as.numeric(), 215.18)
expect_equal(data$low[end.date, "AAPL"] %>% as.numeric(), 209.27)
expect_equal(data$close[end.date, "AAPL"] %>% as.numeric(), 213.30)
expect_equal(data$dividend[start.date, "CBAN"] %>% as.numeric(), 0.05)
})
test_that("function check inputs correctly.", {
expect_error(getSliceDataSharadar(settings$sharadar.sqli,
"close",
start.date = "hoge"),
"character string is not in a standard unambiguous format")
expect_error(getSliceDataSharadar(settings$sharadar.sqli,
"close",
end.date = "fuga"),
"character string is not in a standard unambiguous format")
expect_error(getSliceDataSharadar(settings$sharadar.sqli,
columns = "hoge"),
"hoge is not supported column.")
expect_error(getSliceDataSharadar(settings$sharadar.sqli,
columns = "close",
start.date = "1950-01-01",
end.date = "1950-12-31"),
"*No data found for close. (1950-01-01 - 1950-12-31)*")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.