tests/testthat/test-covariance.R

data("dar.adj.matrix",  package = "BSBT")


test_that("constrained adjacent covariance works", {
  expect_error(constrained_adjacency_covariance_function(dar.adj.matrix,
                                              type = "se",
                                              hyperparameters = c(1, 0.5),
                                              linear.combination = rep(1, 452),
                                              linear.constraint = 0),
          "Could not construct covariance matrix. Unrecognised covariance type")
  expect_error(constrained_adjacency_covariance_function(dar.adj.matrix,
                                              type = "sqexp",
                                              hyperparameters = c(1, 0.5, 1.5),
                                              linear.combination = rep(1, 452),
                                              linear.constraint = 0),
         "Insufficient hyperparameters. Squared Exponential requires 2 values.")
  expect_error(constrained_adjacency_covariance_function(dar.adj.matrix,
                                              type = "sqexp",
                                              hyperparameters = c(1, 0.5),
                                              linear.combination = rep(1, 41),
                                                        linear.constraint = 0),
   "Could not constrain distirbution. Linear constraint dimensions does not match number of objects.")
  expect_error(constrained_adjacency_covariance_function(dar.adj.matrix,
                                              type = "matrix",
                                              hyperparameters = c(1),
                                              linear.combination = rep(1, 41),
                                              linear.constraint = 0),
          "Insufficient hyperparameters. Matrix exponential requires 2 values.")
})

coords <- data.frame("x" = runif(10), "y" = runif(10))

test_that("constrained covariance works", {
  expect_error(constrained_covariance_function(coords, type = "se",
                                               hyperparameters = c(1, 0.5),
                                               linear.combination = rep(1, 10),
                                               linear.constraint = 0),
          "Could not construct covariance matrix. Unrecognised covariance type")
  expect_error(constrained_covariance_function(coords, type = "sqexp",
                                              hyperparameters = c(1, 0.5, 1.5),
                                              linear.combination = rep(1, 10),
                                              linear.constraint = 0),
        "Insufficient hyperparameters. Squared Exponential requires 2 values.")
  expect_error(constrained_covariance_function(coords, type = "sqexp",
                                               hyperparameters = c(1, 0.5),
                                               linear.combination = rep(1, 41),
                                              linear.constraint = 0),
        "Could not constrain distirbution. Linear constraint dimensions does not match number of objects.")
})

Try the BSBT package in your browser

Any scripts or data that you put into this service are public.

BSBT documentation built on Aug. 9, 2022, 5:06 p.m.