diff --git a/DESCRIPTION b/DESCRIPTION index 60f2cacc6..4b5c2f90a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dodgr Title: Distances on Directed Graphs -Version: 0.2.14.092 +Version: 0.2.14.093 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Andreas", "Petutschnig", role = "aut"), diff --git a/codemeta.json b/codemeta.json index d91d03c46..b48506dbb 100644 --- a/codemeta.json +++ b/codemeta.json @@ -7,7 +7,7 @@ "codeRepository": "https://github.com/ATFutures/dodgr", "issueTracker": "https://github.com/ATFutures/dodgr/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.2.14.092", + "version": "0.2.14.093", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-match-pts-fns.R b/tests/testthat/test-match-pts-fns.R index 42efed7a7..5b9348150 100644 --- a/tests/testthat/test-match-pts-fns.R +++ b/tests/testthat/test-match-pts-fns.R @@ -6,7 +6,7 @@ skip_if (!test_all) dodgr_cache_off () clear_dodgr_cache () -test_that ("points to graph", { +test_that ("points to verts", { bb <- attr (hampi$geometry, "bbox") n <- 100 @@ -64,3 +64,71 @@ test_that ("points to graph", { # match on the "$" symbol }) + +test_that ("points to graph", { + + bb <- attr (hampi$geometry, "bbox") + n <- 100 + x <- bb [1] + (bb [3] - bb [1]) * runif (n) + y <- bb [2] + (bb [4] - bb [2]) * runif (n) + pts <- data.frame (x = x, y = y) + net <- weight_streetnet (hampi) + verts <- dodgr_vertices (net) + + expect_error ( + match_pts_to_graph (verts, pts), + "Points may only be matched to spatial graphs." + ) + + expect_silent (index1 <- match_pts_to_graph (net, pts)) + + colnames (pts) <- NULL + expect_message ( + index2 <- match_pts_to_graph (net, pts), + "xy has no named columns; assuming order is x then y" + ) + expect_identical (index1, index2) + + pts <- data.frame (x = x, y = y, x2 = x) + expect_error ( + match_pts_to_graph (net, list (pts)), + "xy must be a matrix or data.frame" + ) + expect_error ( + match_pts_to_graph (net, pts), + "xy must have only two columns" + ) + + pts <- data.frame (x = x, y = y) + expect_silent (index4 <- match_pts_to_graph (net, pts, connected = TRUE)) + expect_true (!identical (index1, index4)) + + class (pts) <- c (class (pts), "tbl") + expect_silent (index5 <- match_pts_to_graph (net, pts, connected = TRUE)) + expect_identical (index4, index5) + + pts <- sf::st_as_sf (pts, coords = c (1, 2), crs = 4326) + expect_silent (index6 <- match_pts_to_graph (net, pts, connected = TRUE)) + expect_identical (index4, index6) + expect_silent (index7 <- match_pts_to_graph (net, pts, connected = TRUE)) + expect_identical (index4, index7) + +}) + +test_that ("add nodes to graph", { + + graph0 <- weight_streetnet (hampi, wt_profile = "foot") + verts <- dodgr_vertices (graph0) + set.seed (1) + npts <- 10 + xy <- data.frame ( + x = min (verts$x) + runif (npts) * diff (range (verts$x)), + y = min (verts$y) + runif (npts) * diff (range (verts$y)) + ) + + graph1 <- add_nodes_to_graph (graph0, xy) + + expect_identical (colnames (graph0), colnames (graph1)) + expect_true ((nrow (graph1) - nrow (graph0)) > npts) + # actually equals 2 * npts when all edges are bi-directional. +})