Skip to content

Commit

Permalink
Improving test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonfreitas committed May 13, 2022
1 parent 04a6ea6 commit 016f649
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 79 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* created documentation site with pkgdown
* rbcb_get implemented for SGS API, it is being used as the infrastruture for get_series (Issue #17)
* organized code
* NAMESPACE organized
* upgraded tests to testthat 3

# rbcb 0.1.10

Expand Down
14 changes: 0 additions & 14 deletions tests/testthat/test-12-months-inflation.R

This file was deleted.

21 changes: 21 additions & 0 deletions tests/testthat/test-currencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,25 @@ test_that("it should get ask/bid time series named with symbol", {
expect_equal(colnames(x_ask), "USD")
x_bid <- Bid(x)
expect_equal(colnames(x_bid), "USD")
})

test_that("it should get cross currency rates", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- get_currency_cross_rates("2017-03-10")
d <- dim(x)
expect_equal(d[1], d[2])
})

test_that("it should list currencies", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- list_currencies()
expect_s3_class(x, "data.frame")
})
13 changes: 0 additions & 13 deletions tests/testthat/test-focus-annual.R

This file was deleted.

38 changes: 0 additions & 38 deletions tests/testthat/test-focus-monthly.R

This file was deleted.

14 changes: 0 additions & 14 deletions tests/testthat/test-focus-quarterly.R

This file was deleted.

163 changes: 163 additions & 0 deletions tests/testthat/test-market-expectations.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
test_that("it should fetch data from 12-months-infl market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IPCA"
start_date <- "2018-06-22"
end_date <- "2018-06-22"
x <- get_twelve_months_inflation_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(NROW(x), 4)
expect_equal(max(x$date), as.Date("2018-06-22"))
})

test_that("it should fetch data from annual market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "Balança comercial"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_annual_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from monthly market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IPCA"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_monthly_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from monthly market expectations API without start_date", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IPCA"
end_date <- "2018-01-31"
x <- get_monthly_market_expectations(indic, end_date = end_date, `$top` = 10)
expect_s3_class(x, "data.frame")
})

test_that("it should fetch data from monthly market expectations API without end_date", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IPCA"
start_date <- "2018-01-02"
x <- get_monthly_market_expectations(indic, start_date = start_date)
expect_s3_class(x, "data.frame")
expect_equal(min(x$date), as.Date("2018-01-02"))
})

test_that("it should fetch data from quarterly market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "PIB Total"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_quarterly_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 10)
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from top 5s monthly market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IGP-M"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_top5s_monthly_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 9)
expect_equal(max(x$date), as.Date("2018-01-31"))

# empty case
indic <- "Selic"
start_date <- "2022-01-01"
end_date <- "2022-04-30"
x <- get_top5s_monthly_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 0)
})

test_that("it should fetch data from top 5s annual market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IGP-M"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_top5s_annual_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 9)
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from institutions market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

indic <- "IGP-M"
start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_institutions_market_expectations(indic, start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 7)
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from selic market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_selic_market_expectations(start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 10)
expect_equal(max(x$date), as.Date("2018-01-31"))
})

test_that("it should fetch data from top 5s selic market expectations API", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

start_date <- "2018-01-01"
end_date <- "2018-01-31"
x <- get_top5s_selic_market_expectations(start_date, end_date)
expect_s3_class(x, "data.frame")
expect_equal(dim(x)[2], 10)
expect_equal(max(x$date), as.Date("2018-01-31"))
})
71 changes: 71 additions & 0 deletions tests/testthat/test-odata-currency.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
test_that("it should test odata currency", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- olinda_get_currency("USD", "2017-03-01", "2017-03-02")
expect_s3_class(x, "data.frame")
expect_equal(attr(x, "symbol"), "USD")

bid <- Bid(x)
ask <- Ask(x)
expect_equal(names(bid), c("datetime", "USD"))
expect_equal(names(ask), c("datetime", "USD"))

x <- olinda_get_currency("USD", "2017-03-01", "2017-03-14", as = "xts")
expect_s3_class(x, "xts")
expect_equal(attr(x, "symbol"), "USD")

x_ask <- Ask(x)
x_bid <- Bid(x)
expect_equal(colnames(x_ask), "USD")
expect_equal(colnames(x_bid), "USD")
})

test_that("it should test odata currency for single date", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- olinda_get_currency("USD", "2017-03-01")
expect_s3_class(x, "data.frame")
expect_equal(attr(x, "symbol"), "USD")
expect_equal(as.Date(max(x$datetime)), as.Date("2017-03-01"))
})

test_that("it should test odata currency with parity", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- olinda_get_currency("USD", "2017-03-01", parity = TRUE)
expect_s3_class(x, "data.frame")
expect_equal(attr(x, "symbol"), "USD")
expect_equal(as.Date(max(x$datetime)), as.Date("2017-03-01"))
expect_true(all(x$bid == 1))
expect_equal(x$bid, x$ask)
})

test_that("it should test odata currency as text", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- olinda_get_currency("USD", "2017-03-01", parity = TRUE, as = "text")
expect_type(x, "character")
})

test_that("it should test odata list currencis", {
if (!covr::in_covr()) {
skip_on_cran()
skip_if_offline()
}

x <- olinda_list_currencies()
expect_s3_class(x, "data.frame")
expect_equal(dim(x), c(10, 3))
})

0 comments on commit 016f649

Please sign in to comment.