tests/testthat/test_make_downward_null.R

library(testthat)
library(domstruc)

a_matrix <- matrix(
  c(
    0.0, 10.0, 2.0, 18.0, 2.0, 5.0, 40.0, 45.0, 20.0, 31.0,
    1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 2.0, 4.0, 2.0, 2.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 8.0, 11.0, 0.0, 4.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 3.0,
    3.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 9.0, 3.0, 5.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 3.0, 8.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 5.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0
  ),
  nrow = 10, ncol = 10, byrow = TRUE
)

random_null <- matrix(
  c(0, 17.3, 17.3, 17.3, 17.3, 17.3, 17.3, 17.3, 17.3, 17.3,
    1.3, 0, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3,
    0.2, 0.2, 0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2,
    2.4, 2.4, 2.4, 0, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4,
    0.0, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.9, 0.9, 0.9, 0.9, 0.9, 0, 0.9, 0.9, 0.9, 0.9,
    2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 0, 2.5, 2.5, 2.5,
    1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 0, 1.3, 1.3,
    0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0, 0.6,
    0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0),
  nrow = 10, ncol = 10, byrow = TRUE
)

pure_downward_null <- matrix(
  c(0, 0.0, 0.0, 34.6, 0.0, 0.0, 34.6, 34.6, 34.6, 34.6,
    2.1666666666666665, 0, 0.0, 2.1666666666666665, 0.0, 0.0, 2.1666666666666665, 2.1666666666666665, 2.1666666666666665, 2.1666666666666665,
    0.2857142857142857, 0.2857142857142857, 0, 0.2857142857142857, 0.0, 0.0, 0.2857142857142857, 0.2857142857142857, 0.2857142857142857, 0.2857142857142857,
    0.0, 0.0, 0.0, 0, 0.0, 0.0, 6.0, 6.0, 6.0, 6.0,
    0.0, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 0.0, 0.0, 0.0,
    1.125, 1.125, 1.125, 1.125, 0.0, 0, 1.125, 1.125, 1.125, 1.125,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 12.5, 0.0, 12.5,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 13.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 0, 2.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0),
  nrow = 10, ncol = 10, byrow = TRUE
  )


test_that("Fully random downward null is correct", {
  expect_equal(dom_make_downward_null(a_matrix, blur = 1),
               random_null)
})

test_that("Pure downward null is correct", {
  expect_equal(dom_make_downward_null(a_matrix, blur = 0),
               pure_downward_null,
               tolerance = 1e-5)
})
danm0nster/domstruc documentation built on Feb. 12, 2020, 8:58 a.m.