tests/testthat/test_Standard_Functions.R

# gsignal Standard Functions
library(gsignal)
library(testthat)

tol <- 1e-6

# -----------------------------------------------------------------------
# detrend()

test_that("parameters to detrend() are correct", {
  expect_error(detrend())
  expect_error(detrend('invalid'))
  expect_error(detrend(1:10, -1))
  expect_error(detrend(1:10, 'invalid'))
  expect_error(detrend(1:10, 0, 1))
})

test_that("detrend() tests are correct", {
  N <- 32
  x <- seq(0, N - 1, 1) / N + 2
  y <- detrend (x)
  expect_true(all(abs(y) < tol))
  
  N <- 32
  t <- seq(0, N - 1, 1) / N
  x <- t * t + 2
  y <- detrend (x, 2)
  expect_true(all(abs(y) < tol))
  
  N <- 32
  t <- seq(0, N - 1, 1) / N
  x <- cbind(t, 4 * t - 3)
  y <- detrend (x)
  expect_true(all(abs(y) < tol))
})
gjmvanboxtel/gsignal documentation built on Nov. 22, 2023, 8:19 p.m.