test_that("moran_border matches ape::Moran.I when ape is available", { skip_if_not_installed("ape") fl <- field_layout(nx = 6, ny = 4, ntrt = 4, nblk = 3, seed = 5) set.seed(2); fl$resp <- rnorm(24) be <- border_effect(resp ~ trt + blk, data = fl, coords = fl) ref <- ape::Moran.I(be$residuals, be$weights) got <- moran_border(be) expect_equal(got$observed, ref$observed, tolerance = 1e-8) expect_equal(got$expected, ref$expected, tolerance = 1e-8) expect_equal(got$sd, ref$sd, tolerance = 1e-8) expect_equal(got$p.value, ref$p.value, tolerance = 1e-8) }) test_that("moran_border returns the expected structure", { fl <- field_layout(nx = 6, ny = 4, ntrt = 4, nblk = 3, seed = 5) set.seed(2); fl$resp <- rnorm(24) be <- border_effect(resp ~ trt + blk, data = fl, coords = fl) got <- moran_border(be) expect_named(got, c("observed", "expected", "sd", "p.value")) })