diff --git a/R/RQA.R b/R/RQA.R index b81cc12..995d3f8 100644 --- a/R/RQA.R +++ b/R/RQA.R @@ -298,7 +298,7 @@ getHistograms = function(neighs, ntakens, lmin, vmin){ # 2) sort # 3) substract 1 to get C-like indexes for neighbors cneighs = mapply( - function(ith_neighs, i) sort(as.integer(c(i, ith_neighs)) - 1), + function(ith_neighs, i) list(sort(as.integer(c(i, ith_neighs)) - 1)), neighs, seq_along(neighs) ) diff --git a/tests/testthat/test_rqa.R b/tests/testthat/test_rqa.R index 476767f..d14902f 100644 --- a/tests/testthat/test_rqa.R +++ b/tests/testthat/test_rqa.R @@ -1,7 +1,33 @@ library(nonlinearTseries) context("RQA") -test_that("test rqa", { +test_that("empty RQA", { + ts = seq(0, 10) + ts_rqa = rqa(time.series = ts, embedding.dim = 2, time.lag = 1, radius = 0.1) + rmatrix = as.matrix(ts_rqa$recurrence.matrix) + expect_true(all(rmatrix == diag(ncol(rmatrix)))) + expect_true( + all(head(ts_rqa$diagonalHistogram, -1) == 0) + ) +}) + +test_that("full RQA", { + ts = seq(0, 10) + ts_rqa = rqa(time.series = ts, embedding.dim = 2, time.lag = 1, radius = 10, + lmin = 1) + rmatrix = as.matrix(ts_rqa$recurrence.matrix) + expect_true(all(rmatrix == 1)) + # expected_diag = c(2,2,2,..., 1) + expected_diag = rep(2, ncol(rmatrix)) + expected_diag[length(expected_diag)] = 1 + expect_equal(ts_rqa$diagonalHistogram, expected_diag) + expected_vertical = rep(0, ncol(rmatrix)) + expected_vertical[ncol(rmatrix)] = ncol(rmatrix) + expect_equal(ts_rqa$verticalHistogram, expected_vertical) +}) + + +test_that("handmade RQA", { skip_on_cran() set.seed(1) # Test 1