Skip to content

Commit

Permalink
fix: closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Feb 1, 2024
1 parent 603b8e4 commit ac13c05
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 63 deletions.
1 change: 0 additions & 1 deletion tests/testthat/setup.R

This file was deleted.

38 changes: 20 additions & 18 deletions tests/testthat/test-currency.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
httptest::with_mock_api({
test_that("output from currency converter is as expected", {
testthat::skip_on_cran()

trend <- currency_converter('GBP', 'USD', '2022-07-01', '2022-07-5', '1d')
expect_equal(nrow(trend), 3)
expect_equal(round(trend$high, 2), c(1.22, 1.22, 1.21))
expect_equal(round(trend$low, 2), c(1.20, 1.21, 1.19))


trend3 <- currency_converter(from = 'GBP',
to = 'USD',
period = '5d',
interval = '1d')
expect_equal(nrow(trend3), 5)
expect_equal(round(trend3$high, 2), c(1.18, 1.17, 1.16, 1.16, 1.15))
expect_equal(round(trend3$low, 2), c(1.16, 1.16, 1.15, 1.15, 1.14))
if (requireNamespace("httptest", quietyly = TRUE)) {
httptest::with_mock_api({
test_that("output from currency converter is as expected", {
testthat::skip_on_cran()

trend <- currency_converter('GBP', 'USD', '2022-07-01', '2022-07-5', '1d')
expect_equal(nrow(trend), 3)
expect_equal(round(trend$high, 2), c(1.22, 1.22, 1.21))
expect_equal(round(trend$low, 2), c(1.20, 1.21, 1.19))


trend3 <- currency_converter(from = 'GBP',
to = 'USD',
period = '5d',
interval = '1d')
expect_equal(nrow(trend3), 5)
expect_equal(round(trend3$high, 2), c(1.18, 1.17, 1.16, 1.16, 1.15))
expect_equal(round(trend3$low, 2), c(1.16, 1.16, 1.15, 1.15, 1.14))
})
})
})
}



Expand Down
28 changes: 15 additions & 13 deletions tests/testthat/test-index.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
httptest::with_mock_api({
test_that("output from index history is as expected", {
testthat::skip_on_cran()
nifty <- Index$new('^NSEI')
trend <- nifty$get_history(start = '2022-07-01',
end = '2022-07-10',
interval = '1d')
expect_equal(nrow(trend), 6)
expect_equal(round(trend$high, 2),
c(15793.95, 15852.35, 16025.75, 16011.35, 16150.50, 16275.50))
expect_equal(round(trend$close, 2),
c(15752.05, 15835.35, 15810.85, 15989.80, 16132.90, 16220.60))
if (requireNamespace("httptest", quietyly = TRUE)) {
httptest::with_mock_api({
test_that("output from index history is as expected", {
testthat::skip_on_cran()
nifty <- Index$new('^NSEI')
trend <- nifty$get_history(start = '2022-07-01',
end = '2022-07-10',
interval = '1d')
expect_equal(nrow(trend), 6)
expect_equal(round(trend$high, 2),
c(15793.95, 15852.35, 16025.75, 16011.35, 16150.50, 16275.50))
expect_equal(round(trend$close, 2),
c(15752.05, 15835.35, 15810.85, 15989.80, 16132.90, 16220.60))
})
})
})
}

test_that("index are properly validated", {
testthat::skip_on_cran()
Expand Down
22 changes: 12 additions & 10 deletions tests/testthat/test-market-summary.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
httptest::with_mock_api({
test_that("output from market summary is as expected", {
testthat::skip_on_cran()
trend <- get_market_summary()
expect_equal(length(trend[[1]]), 29)
expect_equal(trend[[1]]$fullExchangeName, "CME")
expect_equal(trend[[1]]$symbol, "ES=F")
expect_equal(trend[[1]]$quoteType, "FUTURE")
expect_equal(trend[[1]]$regularMarketPrice$raw, 4159.25)
if (requireNamespace("httptest", quietyly = TRUE)) {
httptest::with_mock_api({
test_that("output from market summary is as expected", {
testthat::skip_on_cran()
trend <- get_market_summary()
expect_equal(length(trend[[1]]), 29)
expect_equal(trend[[1]]$fullExchangeName, "CME")
expect_equal(trend[[1]]$symbol, "ES=F")
expect_equal(trend[[1]]$quoteType, "FUTURE")
expect_equal(trend[[1]]$regularMarketPrice$raw, 4159.25)
})
})
})
}
30 changes: 16 additions & 14 deletions tests/testthat/test-ticker.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
httptest::with_mock_api({
test_that("output from get history is as expected", {
testthat::skip_on_cran()
aapl <- Ticker$new('aapl')
trend <- aapl$get_history(start = '2022-09-01',
end = '2022-09-05',
interval = '1d')
if (requireNamespace("httptest", quietyly = TRUE)) {
httptest::with_mock_api({
test_that("output from get history is as expected", {
testthat::skip_on_cran()
aapl <- Ticker$new('aapl')
trend <- aapl$get_history(start = '2022-09-01',
end = '2022-09-05',
interval = '1d')

expect_equal(nrow(trend), 2)
expect_equal(as.Date(trend$date), as.Date(c("2022-09-01", "2022-09-02")))
expect_equal(round(trend$high, 2), c(158.42, 160.36))
expect_equal(round(trend$low, 2), c(154.67, 154.97))
expect_equal(round(trend$open, 2), c(156.64, 159.75))
expect_equal(round(trend$close, 2), c(157.96, 155.81))
expect_equal(nrow(trend), 2)
expect_equal(as.Date(trend$date), as.Date(c("2022-09-01", "2022-09-02")))
expect_equal(round(trend$high, 2), c(158.42, 160.36))
expect_equal(round(trend$low, 2), c(154.67, 154.97))
expect_equal(round(trend$open, 2), c(156.64, 159.75))
expect_equal(round(trend$close, 2), c(157.96, 155.81))

})
})
})
}

test_that("symbols are properly validated", {
testthat::skip_on_cran()
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test-trending.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
httptest::with_mock_api({
test_that("output from trending securities is as expected", {
testthat::skip_on_cran()
trend <- get_trending(country = "US", count = 5)
expect_equal(length(trend), 5)
expect_equal(trend, c("BBBY", "PTON", "SOFI", "JWN", "STBX"))
if (requireNamespace("httptest", quietyly = TRUE)) {
httptest::with_mock_api({
test_that("output from trending securities is as expected", {
testthat::skip_on_cran()
trend <- get_trending(country = "US", count = 5)
expect_equal(length(trend), 5)
expect_equal(trend, c("BBBY", "PTON", "SOFI", "JWN", "STBX"))
})
})
})
}

test_that("output is as expected in case of no trending securities", {
testthat::skip_on_cran()
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
test_that("output from validate is as expected", {
testthat::skip_on_cran()
expect_true(validate("aapl"))
})

test_that("output from validate is as expected when symbol is wrong", {
testthat::skip_on_cran()
expect_false(validate("aapls"))
})

0 comments on commit ac13c05

Please sign in to comment.