Skip to content

Instantly share code, notes, and snippets.

@eddyrene
Created August 11, 2021 02:59
Show Gist options
  • Save eddyrene/4fff7d961a2453bd6e03538eb13dd93f to your computer and use it in GitHub Desktop.
Save eddyrene/4fff7d961a2453bd6e03538eb13dd93f to your computer and use it in GitHub Desktop.
source("../code.R", chdir = TRUE)
library(testthat)
#testthat::test_dir("tests")
d_usd = 1-0.25
d_eur = 1-0.2
d_day = 0.5
order <- readxl::read_xlsx("../data_test.xlsx", "columnas")
test_that("columnas", {
expect_equal(totalPrice(order,"USD",Sys.Date()), 1482* d_usd)
expect_equal(totalPrice(order,"EUR",Sys.Date()), 1296*d_eur)
})
## date selected
order <- readxl::read_xlsx("../data_test.xlsx", "columnas")
test_that("exact date", {
expect_equal(totalPrice(order,"USD","2020-11-27"), 1482* d_day)
expect_equal(totalPrice(order,"EUR","2020-11-27"), 1296*d_day)
})
order <- readxl::read_xlsx("../data_test.xlsx", "duplicados")
test_that("duplicados", {
expect_equal(totalPrice(order,"USD",Sys.Date()), 1482* d_usd)
expect_equal(totalPrice(order,"EUR",Sys.Date()), 1296* d_eur)
})
order <- readxl::read_xlsx("../data_test.xlsx", "negativos")
test_that("empty vector", {
expect_equal(totalPrice(order,"USD",Sys.Date()), 4961*d_usd)
expect_equal(totalPrice(order,"EUR",Sys.Date()), 1773*d_eur)
})
order <- readxl::read_xlsx("../data_test.xlsx", "na")
test_that("test NA", {
expect_equal(totalPrice(order,"USD",Sys.Date()),4961*d_usd)
expect_equal(totalPrice(order,"EUR",Sys.Date()),1494*d_eur)
expect_error(totalPrice(NA,NA,Sys.Date()))
expect_error(totalPrice(NA,NA,NA))
})
order <- readxl::read_xlsx("../data_test.xlsx", "null")
test_that("NULL", {
expect_warning(totalPrice(order,"USD",Sys.Date()))
expect_error(totalPrice(NULL,"USD",Sys.Date()))
expect_error(totalPrice(NULL,"EUR",Sys.Date()))
expect_error(totalPrice(NULL,NA,Sys.Date()))
expect_error(totalPrice(NULL,NA,Sys.Date()))
})
# others currencies
order <- readxl::read_xlsx("../data_test.xlsx", "columnas")
test_that("other currencies", {
expect_equal(totalPrice(order,"RUP","2020-11-28"), 605)
expect_equal(totalPrice(order,"BOL","2020-11-28"), 6125)
expect_error(totalPrice(order,"REAL","2020-11-28"))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment