## 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 ## three_black_crows and CDL3BLACKCROWS 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 <- three_black_crows(SPY) alias <- CDL3BLACKCROWS(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(three_black_crows(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(three_black_crows(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 = three_black_crows( BTC ), expected = three_black_crows( BTC, cols = ~ open + high + low + 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(three_black_crows( 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 <- three_black_crows(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(three_black_crows( 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 <- three_black_crows(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(three_black_crows( 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 <- three_black_crows(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 three_black_crows can ## use without any issues output <- testthat::expect_no_error( { chart(BTC) indicator(three_black_crows) } ) ## check that the output ## is a -object testthat::expect_true( inherits(output, "plotly") ) }) ## checks testthat::test_that(desc = '-methods for ', code = { ## check that three_black_crows can ## use without any issues output <- testthat::expect_no_error( { chart(SPY) indicator(three_black_crows) } ) ## 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 three_black_crows 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(three_black_crows) } ) ## 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 three_black_crows 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(three_black_crows) } ) ## check that the output ## is a -object or testthat::expect_true( inherits(output, "gg") || inherits(output, "talib_chart") ) })