tests/testthat/test-NAs.R

library(AnomalyDetection)

context("Testing NAs")

test_that("check handling of datasets with leading and trailing NAs", {
  data(raw_data)
  raw_data[1:10, "count"] <- NA
  raw_data[length(raw_data[[2L]]), "count"] <- NA
  results <- AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both')
  expect_equal(length(results), 2)
  expect_equal(length(results[[2L]]), 131)
})

test_that("check handling of datasets with NAs in the middle", {
  data(raw_data)
  raw_data[floor(length(raw_data[[2L]])/2), "count"] <- NA
  expect_error(AnomalyDetectionTs(raw_data, max_anoms=0.02, direction='both'))
})

test_that("check handling of datasets with leading and trailing NAs", {
  data(raw_data)
  raw_data[1:10, "count"] <- NA
  raw_data[length(raw_data[[2L]]), "count"] <- NA
  results <- AnomalyDetectionVec(raw_data[[2]], max_anoms=0.02, period=1440, direction='both')
  expect_equal(length(results), 2)
  expect_equal(length(results[[2L]]), 131)
})

test_that("check handling of datasets with NAs in the middle", {
  data(raw_data)
  raw_data[floor(length(raw_data[[2L]])/2), "count"] <- NA
  expect_error(AnomalyDetectionVec(raw_data[[2L]], max_anoms=0.02,
                                   period=1440, direction='both'))
})
Harminder858/anomaly_twitter_harminder documentation built on March 29, 2020, 5:33 a.m.