Nothing
# Data for tests ----
sites <- expand.grid("transect" = 1:5,
"quadrat" = 1:5)
nodes <- create_node_labels(data = sites,
transect = "transect",
quadrat = "quadrat")
sites_qu <- expand.grid("transect" = 3,
"quadrat" = 1:5)
nodes_qu <- create_node_labels(data = sites_qu,
transect = "transect",
quadrat = "quadrat")
sites_tr <- expand.grid("transect" = 1:5,
"quadrat" = 3)
nodes_tr <- create_node_labels(data = sites_tr,
transect = "transect",
quadrat = "quadrat")
# Tests for errors ----
test_that("knight() - Tests for errors", {
expect_error(knight(),
paste0("Argument 'nodes' is required (output of the function ",
"create_node_labels())"),
fixed = TRUE)
expect_error(knight(nodes_qu),
paste0("The knight movement is not designed to work through ",
"quadrats only. Please use pawn() instead."),
fixed = TRUE)
expect_error(knight(nodes_tr),
paste0("The knight movement is not designed to work through ",
"transects only. Please use fool() instead."),
fixed = TRUE)
})
# Tests for success ----
test_that("knight() - Tests for success (2D network)", {
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 1,
directed = TRUE,
reverse = FALSE,
self = FALSE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 0L)
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 2,
directed = TRUE,
reverse = FALSE,
self = FALSE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 4L)
expect_equal(neighbors[ , "node"], c("1-4", "2-5", "4-5", "5-4"))
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 3,
directed = TRUE,
reverse = FALSE,
self = FALSE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 4L)
expect_equal(neighbors[ , "node"], c("1-4", "2-5", "4-5", "5-4"))
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 2,
directed = TRUE,
reverse = TRUE,
self = FALSE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 4L)
expect_equal(neighbors[ , "node"], c("1-2", "2-1", "4-1", "5-2"))
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 2,
directed = FALSE,
reverse = FALSE,
self = FALSE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 8L)
expect_equal(neighbors[ , "node"], c("1-2", "1-4", "2-1", "2-5", "4-1", "4-5",
"5-2", "5-4"))
expect_silent({
neighbors <- knight(nodes,
focus = "3-3",
degree = 2,
directed = FALSE,
reverse = FALSE,
self = TRUE)
})
expect_equal(class(neighbors), "data.frame")
expect_equal(ncol(neighbors), 4L)
expect_equal(nrow(neighbors), 8L)
expect_equal(neighbors[ , "node"], c("1-2", "1-4", "2-1", "2-5", "4-1", "4-5",
"5-2", "5-4"))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.