tests/testthat/test_moin_network.R

library(moin)

context("moin_network")

test_that("correct class", {
  set.seed(1985)
  d <- data.frame(matrix(runif(15), ncol = 3))
  p <- sf::st_as_sf(x = d, coords = 1:2)
  result <- moin_network(input = p, method = "mdm", par = 0.3)
  expect_equal(class(result), class(list()))
})

test_that("correct result", {
  set.seed(1985)
  d <- data.frame(matrix(runif(15), ncol = 3))
  p <- sf::st_as_sf(x = d, coords = 1:2)
  result <- moin_network(input = p, method = "mdm", par = 0.3)
  expected_matrix <- matrix(c(0.0000000, 0.5695746, 0.6135593, 0.7839556, 0.4770481, 0.5695746,
                              0.0000000, 0.1653786, 0.3694325, 0.1139927, 0.6135593, 0.1653786,
                              0.0000000, 0.5203397, 0.2538972, 0.7839556, 0.3694325, 0.5203397,
                              0.0000000, 0.3656017, 0.4770481, 0.1139927, 0.2538972, 0.3656017,
                              0.0000000),ncol=5)
  expect_equal(round(result$distance_matrix,3), round(expected_matrix,3))
})
CRC1266-A2/moin documentation built on May 7, 2019, 8:56 p.m.