diff --git a/R/allShortestPaths.R b/R/allShortestPaths.R index 5ec0e2c..ac6b8c7 100644 --- a/R/allShortestPaths.R +++ b/R/allShortestPaths.R @@ -5,7 +5,7 @@ #' @param fromNode A node object. #' @param relType A character string. The relationship type to traverse. #' @param toNode A node object. -#' @param direction A character string. The relationship direction to traverse. Should be "in" or "out". +#' @param direction A character string. The relationship direction to traverse; this can be either "in", "out", or "all". #' @param max_depth An integer. The maximum depth of the path. #' @param cost_property A character string. If retrieving a weighted shortest path, the name of the relationship property that contains the weights. #' diff --git a/R/internal.R b/R/internal.R index f6d5afc..38672b7 100644 --- a/R/internal.R +++ b/R/internal.R @@ -170,7 +170,7 @@ cypher_endpoint = function(graph, query, params) { shortest_path_algo = function(all, algo, fromNode, relType, toNode, direction = "out", max_depth = 1, cost_property=character()) { stopifnot(is.character(relType), "node" %in% class(toNode), - direction %in% c("in", "out"), + direction %in% c("in", "out", "all"), is.numeric(max_depth), is.character(cost_property)) diff --git a/R/shortestPath.R b/R/shortestPath.R index 3e73842..111c3ca 100644 --- a/R/shortestPath.R +++ b/R/shortestPath.R @@ -5,7 +5,7 @@ #' @param fromNode A node object. #' @param relType A character string. The relationship type to traverse. #' @param toNode A node object. -#' @param direction A character string. The relationship direction to traverse. Should be "in" or "out". +#' @param direction A character string. The relationship direction to traverse; this can be either "in", "out", or "all". #' @param max_depth An integer. The maximum depth of the path. #' @param cost_property A character string. If retrieving a weighted shortest path, the name of the relationship property that contains the weights. #' diff --git a/man/allShortestPaths.Rd b/man/allShortestPaths.Rd index 59ef763..333d8fd 100644 --- a/man/allShortestPaths.Rd +++ b/man/allShortestPaths.Rd @@ -14,7 +14,7 @@ allShortestPaths(fromNode, relType, toNode, direction = "out", \item{toNode}{A node object.} -\item{direction}{A character string. The relationship direction to traverse. Should be "in" or "out".} +\item{direction}{A character string. The relationship direction to traverse; this can be either "in", "out", or "all".} \item{max_depth}{An integer. The maximum depth of the path.} diff --git a/man/shortestPath.Rd b/man/shortestPath.Rd index 7456b3c..2fcc823 100644 --- a/man/shortestPath.Rd +++ b/man/shortestPath.Rd @@ -14,7 +14,7 @@ shortestPath(fromNode, relType, toNode, direction = "out", max_depth = 1, \item{toNode}{A node object.} -\item{direction}{A character string. The relationship direction to traverse. Should be "in" or "out".} +\item{direction}{A character string. The relationship direction to traverse; this can be either "in", "out", or "all".} \item{max_depth}{An integer. The maximum depth of the path.} diff --git a/tests/testthat/test-paths.R b/tests/testthat/test-paths.R index 91944a2..e54e7c5 100644 --- a/tests/testthat/test-paths.R +++ b/tests/testthat/test-paths.R @@ -49,6 +49,17 @@ test_that("shortestPath works with direction=in", { expect_equal(actual_names, expected_names) }) +test_that("shortestPath works with direction=all", { + p = shortestPath(charles, "WORKS_WITH", elaine, direction = "all", max_depth = 4) + expect_is(p, "path") + expect_equal(p$length, 2) + + n = nodes(p) + actual_names = sapply(n, '[[', 'name') + expected_names = c("Charles", "David", "Elaine") + expect_equal(actual_names, expected_names) +}) + test_that("allShortestPaths returns null when not found", { p = allShortestPaths(alice, "WORKS_WITH", david) expect_null(p) @@ -57,18 +68,27 @@ test_that("allShortestPaths returns null when not found", { expect_null(p) }) -test_that("allShortestPaths works", { - p = allShortestPaths(alice, "WORKS_WITH", david, max_depth = 4) +test_that("allShortestPaths works with direction=out", { + p = allShortestPaths(alice, "WORKS_WITH", david, direction = "out", max_depth = 4) expect_is(p, "list") expect_is(p[[1]], "path") expect_equal(length(p), 2) - +}) + +test_that("allShortestPaths works with direction=in", { p = allShortestPaths(david, "WORKS_WITH", alice, direction = "in", max_depth = 4) expect_is(p, "list") expect_is(p[[1]], "path") expect_equal(length(p), 2) }) +test_that("allShortestPaths works with direction=all", { + p = allShortestPaths(bob, "WORKS_WITH", elaine, direction = "all", max_depth = 4) + expect_is(p, "list") + expect_is(p[[1]], "path") + expect_equal(length(p), 2) +}) + test_that("shortestPath works with cost property", { p = shortestPath(alice, "WORKS_WITH", david, cost_property="weight")