## autogenerated unit-test ## from codegen/generate_unit-tests.sh ## the file will be overwritten in the next iteration ## ## author: Serkan Korkmaz ## alias and function similarity ## checks this ensures that ## ratio_of_change and ROCR produces the same results testthat::test_that(desc = 'Alias and function similarity', code = { ## 1) test that the alias and ## function returns the same values output <- ratio_of_change(SPY) alias <- ROCR(SPY) ## 1.1) check if the values ## are equal testthat::expect_equal( object = output, expected = alias ) }) ## type-checks for data.frames and ## matrices ## ## object testthat::test_that(desc = 'Class in, class out ()', code = { ## 1) check that the output class ## matches the input class testthat::expect_true( inherits(ratio_of_change(SPY), class(SPY)) ) }) ## object testthat::test_that(desc = 'Class in, class out ()', code = { ## 1) check that the output class ## matches the input class testthat::expect_true( inherits(ratio_of_change(BTC), class(BTC)) ) }) ## check that the default calls ## matches that of the constructed call ## with default values. ## ## NOTE: This test is more of a test of the internal ## series() function testthat::test_that(desc = 'Default calls', code = { testthat::expect_equal( object = ratio_of_change( BTC ), expected = ratio_of_change( BTC, cols = ~close ) ) }) ## check that the length of the input ## matches the output length with na.bridge = TRUE ## ## object testthat::test_that(desc = 'Equal length of input and output for with na.bridge = TRUE', code = { testthat::expect_equal( object = nrow(ratio_of_change( ATOM, na.bridge = TRUE )), expected = nrow(ATOM) ) }) ## check that the rownames are being ## respected for with na.bridge = TRUE testthat::test_that(desc = 'Row names are respected for , na.bridge = TRUE', code = { ## extract row names x_names <- row.names(ATOM) ## calculate indicator indicator <- ratio_of_change(ATOM, na.bridge = TRUE) testthat::expect_equal( object = x_names, expected = rownames(indicator) ) }) ## check that the length of the input ## matches the output length ## ## object testthat::test_that(desc = 'Equal length of input and output for ', code = { testthat::expect_equal( object = nrow(ratio_of_change( BTC )), expected = nrow(BTC) ) }) ## check that the rownames are being ## respected for testthat::test_that(desc = 'Row names are respected for ', code = { ## extract row names x_names <- row.names(BTC) ## calculate indicator indicator <- ratio_of_change(BTC) testthat::expect_equal( object = x_names, expected = rownames(indicator) ) }) ## object testthat::test_that(desc = 'Equal length of input and output for ', code = { testthat::expect_equal( object = nrow(ratio_of_change( SPY )), expected = nrow(SPY) ) }) ## check that the rownames are being ## respected for testthat::test_that(desc = 'Row names are respected for ', code = { ## extract row names ## NOTE: by default the SPY has no ## rownames rownames(SPY) <- paste0("row", 1:nrow(SPY)) ## calculate indicator indicator <- ratio_of_change(SPY) testthat::expect_equal( object = paste0("row", 1:nrow(SPY)), expected = rownames(indicator) ) }) ## -method checks for ## and ## ## checks testthat::test_that(desc = '-methods for ', code = { ## check that ratio_of_change can ## use without any issues output <- testthat::expect_no_error( { chart(BTC) indicator(ratio_of_change) } ) ## check that the output ## is a -object testthat::expect_true( inherits(output, "plotly") ) }) ## checks testthat::test_that(desc = '-methods for ', code = { ## check that ratio_of_change can ## use without any issues output <- testthat::expect_no_error( { chart(SPY) indicator(ratio_of_change) } ) ## check that the output ## is a -object testthat::expect_true( inherits(output, "plotly") ) }) ## -method checks for ## and ## ## checks testthat::test_that(desc = '-methods for ', code = { testthat::skip_if_not_installed("ggplot2") ## check that ratio_of_change can ## use without any issues output <- testthat::expect_no_error( { options(talib.chart.backend = "ggplot2") on.exit(options(talib.chart.backend = "plotly")) chart(BTC) indicator(ratio_of_change) } ) ## check that the output ## is a -object or testthat::expect_true( inherits(output, "gg") || inherits(output, "talib_chart") ) }) ## checks testthat::test_that(desc = '-methods for ', code = { testthat::skip_if_not_installed("ggplot2") ## check that ratio_of_change can ## use without any issues output <- testthat::expect_no_error( { options(talib.chart.backend = "ggplot2") on.exit(options(talib.chart.backend = "plotly")) chart(SPY) indicator(ratio_of_change) } ) ## check that the output ## is a -object or testthat::expect_true( inherits(output, "gg") || inherits(output, "talib_chart") ) }) ## check that methods runs without ## issues and returns proper lengths testthat::test_that(desc = ' methods', code = { ## check that the method ## runs x <- testthat::expect_no_condition( ratio_of_change(BTC[[1]]) ) ## the numeric methods returns ## depending on the underlying functions ## so the checks for equal lengths is conditional target_length <- length(BTC[[1]]) if (is.null(dim(x))) { testthat::expect_true( length(x) == target_length ) } else { testthat::expect_true( nrow(x) == target_length ) } })