Skip to content

Commit

Permalink
Remove all partial matching cases in test fix business-science#165
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Jun 11, 2024
1 parent ba78708 commit d456bc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/testthat/test-tk_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ library(dplyr)
FB_tbl <- FANG %>% dplyr::filter(symbol == "FB")
FB_xts <- FB_tbl %>% tk_xts(silent = TRUE)
FB_zoo <- FB_tbl %>% tk_zoo(silent = TRUE)
FB_zooreg <- FB_tbl %>% tk_zooreg(start = 2015, freq = 252, silent = TRUE)
FB_ts <- FB_tbl %>% tk_ts(start = 2015, freq = 252, silent = TRUE)
FB_zooreg <- FB_tbl %>% tk_zooreg(start = 2015, frequency = 252, silent = TRUE)
FB_ts <- FB_tbl %>% tk_ts(start = 2015, frequency = 252, silent = TRUE)

# FUNCTION tk_index -----

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-tk_ts.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("xts to ts test returns ts with correct rows and columns.", {

# Error if using date_var field
expect_error(tk_ts(FB_xts, date_var = date,
freq = 252, start = 2015)) # date_var not used
frequency = 252, start = 2015)) # date_var not used

})

Expand All @@ -67,6 +67,6 @@ test_that("zoo to ts test returns ts with correct rows and columns.", {

# Warning if using date_var field
expect_error(tk_ts(FB_xts, date_var = date,
freq = 252, start = 2015)) # date_var not used
frequency = 252, start = 2015)) # date_var not used

})
20 changes: 10 additions & 10 deletions tests/testthat/test-tk_zooreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ FB_xts <- FB_tbl %>% tk_xts(silent = TRUE)
# tbl to zooreg -----
test_that("tbl to zooreg test returns zooreg with correct rows and columns.", {
# Use date column to specify order
test_zooreg_1 <- tk_zooreg(FB_tbl, freq = 252, start = 2015, silent = TRUE)
test_zooreg_1 <- tk_zooreg(FB_tbl, frequency = 252, start = 2015, silent = TRUE)
expect_equal(nrow(test_zooreg_1), 1008)
expect_equal(ncol(test_zooreg_1), 6)
expect_equal(rownames(test_zooreg_1), as.character(FB_tbl$date))

# Use order.by to specify order
test_zooreg_2 <- tk_zooreg(FB_tbl, order.by = FB_tbl$date, freq = 252, start = 2015, silent = TRUE)
test_zooreg_2 <- tk_zooreg(FB_tbl, order.by = FB_tbl$date, frequency = 252, start = 2015, silent = TRUE)
expect_equal(nrow(test_zooreg_2), 1008)
expect_equal(ncol(test_zooreg_2), 6)

# # Auto-index date
# expect_message(tk_zooreg(FB_tbl, freq = 252, start = 2015)) # using `date` column as date
# expect_message(tk_zooreg(FB_tbl, frequency = 252, start = 2015)) # using `date` column as date

# Auto-drop columns
expect_warning(tk_zooreg(FB_tbl, freq = 252, start = 2015)) # dropping date column
expect_warning(tk_zooreg(FB_tbl, frequency = 252, start = 2015)) # dropping date column

# # Auto-index and auto-drop columns
# expect_message(expect_warning(tk_zooreg(FB_tbl, freq = 252, start = 2015))) # using `date` column as date, dropping date column
# expect_message(expect_warning(tk_zooreg(FB_tbl, frequency = 252, start = 2015))) # using `date` column as date, dropping date column

# NSE
select <- "adjusted"
date_var <- "date"
test_zooreg_3 <- tk_zooreg_(FB_tbl, select = select, date_var = date_var,
freq = 252, start = 2015)
frequency = 252, start = 2015)
expect_equal(nrow(test_zooreg_3), 1008)
expect_equal(ncol(test_zooreg_3), 1)
expect_equal(colnames(test_zooreg_3), select)
Expand All @@ -42,7 +42,7 @@ test_that("tbl to zooreg test returns zooreg with correct rows and columns.", {
# Default is xts::xts() for other objects; only test zoo
test_that("xts to zooreg test returns zooreg with correct rows and columns.", {
# Use date column to specify order
test_zooreg_4 <- tk_zooreg(FB_xts, freq = 252, start = 2015, silent = TRUE)
test_zooreg_4 <- tk_zooreg(FB_xts, frequency = 252, start = 2015, silent = TRUE)
expect_equal(nrow(test_zooreg_4), 1008)
expect_equal(ncol(test_zooreg_4), 6)

Expand All @@ -53,14 +53,14 @@ test_that("xts to zooreg test returns zooreg with correct rows and columns.", {

# Warning if using select field
expect_warning(tk_zooreg(FB_xts, select = -date,
freq = 252, start = 2015)) # only for use with data.frames
frequency = 252, start = 2015)) # only for use with data.frames

# Warning if using date_var field
expect_warning(tk_zooreg(FB_xts, date_var = date,
freq = 252, start = 2015)) # only for use with data.frames
frequency = 252, start = 2015)) # only for use with data.frames

# Two warnings: select and date_var args only applicable to data.frames
expect_warning(tk_zooreg(FB_xts, select = -date, date_var = date,
freq = 252, start = 2015))
frequency = 252, start = 2015))

})

0 comments on commit d456bc2

Please sign in to comment.