Skip to content

Commit

Permalink
add tests for module dependency methods (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Jun 10, 2015
1 parent 65fa49f commit 5218320
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions R/module-dependencies-methods.R
Expand Up @@ -108,6 +108,7 @@ setGeneric("depsGraph", function(sim, plot) {
standardGeneric("depsGraph")
})

#' @export
#' @rdname depsGraph
setMethod("depsGraph",
signature(sim="simList", plot="logical"),
Expand All @@ -120,6 +121,14 @@ setMethod("depsGraph",
return(graph.data.frame(el))
})

#' @export
#' @rdname depsGraph
setMethod("depsGraph",
signature(sim="simList", plot="missing"),
definition=function(sim) {
return(depsGraph(sim, FALSE))
})

################################################################################
#' Prune edges to remove cycles in module dependencies
#'
Expand Down
43 changes: 43 additions & 0 deletions tests/testthat/test-module-deps-methods.R
@@ -0,0 +1,43 @@
test_that("depsEdgeList and depsGraph work", {
times <- list(start=0.0, stop=10)
params <- list(.globals=list(burnStats="npixelsburned", stackName="landscape"),
randomLandscapes=list(.plotInitialTime=NA, .plotInterval=NA),
caribouMovement=list(.plotInitialTime=NA, .plotInterval=NA),
fireSpread=list(.plotInitialTime=NA, .plotInterval=NA))
modules <- list("randomLandscapes", "caribouMovement", "fireSpread")
path <- system.file("sampleModules", package="SpaDES")

mySim <- simInit(times, params, modules, objects=list(), path)

# depsEdgeList
el <- depsEdgeList(mySim)
el_from <- c("caribouMovement", "caribouMovement", "fireSpread", "fireSpread",
"fireSpread", "randomLandscapes", "randomLandscapes")
el_to <- c("caribouMovement", "fireSpread", "caribouMovement", "fireSpread",
"fireSpread", "caribouMovement", "fireSpread")
el_objName <- c("landscape", "landscape", "landscape", "landscape", "npixelsburned",
"landscape", "landscape")
el_objClass <- c("RasterStack", "RasterStack", "RasterStack", "RasterStack",
"numeric", "RasterStack", "RasterStack")

expect_is(el, "data.table")
expect_equal(names(el), c("from", "to", "objName", "objClass"))
expect_equal(el$from, el_from)
expect_equal(el$to, el_to)
expect_equal(el$objName, el_objName)
expect_equal(el$objClass, el_objClass)

# .depsPruneEdges
p <- .depsPruneEdges(el)
p_from <- c("randomLandscapes", "randomLandscapes")
p_to <- c("caribouMovement", "fireSpread")
p_objName <- c("landscape", "landscape")
p_objClass <- c("RasterStack", "RasterStack")
p_ <- data.table(from=p_from, to=p_to, objName=p_objName, objClass=p_objClass)

expect_is(p, "data.table")
expect_equivalent(p, p_)

# depsGraph
expect_is(depsGraph(mySim), "igraph")
})

0 comments on commit 5218320

Please sign in to comment.