Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Aug 20, 2024
1 parent 2a7d680 commit 381fc9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/shikokuchuo.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ static void PreserveObjects(void) {
R_PreserveObject(ichimoku_false = Rf_ScalarLogical(0));
}

// # nocov start
static void ReleaseObjects(void) {
R_ReleaseObject(ichimoku_false);
R_ReleaseObject(ichimoku_int_three);
Expand All @@ -397,6 +398,7 @@ static void ReleaseObjects(void) {
R_ReleaseObject(ichimoku_klass);
R_ReleaseObject(ichimoku_dfclass);
}
// # nocov end

static const R_CallMethodDef CallEntries[] = {
{"_coredata", (DL_FUNC) &_coredata, 1},
Expand All @@ -423,6 +425,8 @@ void attribute_visible R_init_ichimoku(DllInfo* dll) {
R_forceSymbols(dll, TRUE);
}

// # nocov start
void attribute_visible R_unload_ichimoku(DllInfo *info) {
ReleaseObjects();
}
// # nocov end
14 changes: 8 additions & 6 deletions tests/testthat/test-strat.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
cloud <- ichimoku(sample_ohlc_data)
strat <- strat(cloud, c1 = "chikou", c2 = "cloudT", dir = "long")
strat2 <- strat(cloud, c1 = "chikou", c2 = "cloudT", c3 = "chikou", c4 = "cloudT", dir = "long")
strat3 <- strat(cloud, c1 = "tenkan", c2 = "kijun", dir = "long")
strat4 <- strat(cloud, c1 = "tenkan", c2 = "kijun", dir = "short")
strat3 <- strat(cloud, c1 = "chikou", c2 = "cloudT", c3 = "chikou", c4 = "cloudT", type = 3)
strat4 <- strat(cloud, c1 = "tenkan", c2 = "kijun", dir = "long")
strat5 <- strat(cloud, c1 = "tenkan", c2 = "kijun", dir = "short")

test_that("strat ok", {
expect_s3_class(strat, "ichimoku")
expect_identical(dim(strat), c(281L, 19L))
expect_identical(strat, strat2)
expect_identical(strat2, strat3)
expect_error(strat(sample_ohlc_data), regexp = "ichimoku object")
expect_error(strat(cloud, "close", "tenkan", "kijun", "chikou", type = "a"), regexp = "type invalid")
})

test_that("stratcombine ok", {
expect_s3_class(comb <- stratcombine(strat, strat3), "ichimoku")
expect_s3_class(comb <- stratcombine(strat, strat4), "ichimoku")
expect_identical(dim(comb), c(281L, 19L))
expect_identical(stratcombine(strat, strat), strat)
expect_error(stratcombine(sample_ohlc_data), regexp = "ichimoku object")
expect_error(stratcombine(strat, strat(cloud[1:100,])), regexp = "same data")
expect_error(stratcombine(strat, strat4), regexp = "Trade direction")
expect_error(stratcombine(strat, strat5), regexp = "Trade direction")
})

test_that("hasStrat ok", {
Expand All @@ -33,6 +35,6 @@ test_that("str method for strat ok", {
test_that("summary method for strat ok", {
expect_type(summary(strat), "list")
expect_output(expect_vector(summary(strat, strat = FALSE), ptype = "character()"), "with dimensions")
attr(strat4, "strat") <- "invalid"
expect_output(summary(strat4), "invalid strategy")
attr(strat5, "strat") <- "invalid"
expect_output(summary(strat5), "invalid strategy")
})

0 comments on commit 381fc9e

Please sign in to comment.