Skip to content

Commit

Permalink
add tests to close #254
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 27, 2024
1 parent 8ca18e0 commit 18532d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.4.1.030
Version: 0.4.1.031
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"codeRepository": "https://github.com/UrbanAnalyst/dodgr",
"issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.4.1.030",
"version": "0.4.1.031",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-dists.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,48 @@ test_that ("all dists", {
expect_equal (nrow (d), nrow (v))
})

test_that ("to-from-as-integerish", {
# Integer-ish to-from cols (#254 from @luukvdmeer)
graph <- data.frame (
from = c (1, 2, 2, 2, 3, 3, 4, 4),
to = c (2, 1, 3, 4, 2, 4, 3, 1),
d = c (1, 2, 1, 3, 2, 1, 2, 1)
)
expect_silent (d0 <- dodgr_dists (graph, from = 1, to = 2))
expect_silent (d1 <- dodgr_dists (graph, from = 1L, to = 2L))
expect_identical (d0, d1)
v <- dodgr_vertices (graph)
# Verts are numeric, but 'graph$from' has them in sequence, so:
expect_identical (v$id, as.numeric (seq_along (unique (graph$from))))

graph <- data.frame (
from = c (1, 3, 2, 2, 3, 3, 4, 4), # no longer in sequence!
to = c (2, 1, 3, 4, 2, 4, 3, 1),
d = c (1, 2, 1, 3, 2, 1, 2, 1)
)
expect_silent (d2 <- dodgr_dists (graph, from = 1, to = 2))
expect_silent (d3 <- dodgr_dists (graph, from = 1L, to = 2L))
v <- dodgr_vertices (graph)
expect_false (identical (v$id, as.numeric (seq_along (unique (graph$from)))))
expect_true (rownames (d2) == "1")
expect_true (rownames (d3) == "1")
expect_false (colnames (d2) == "2")
expect_false (colnames (d3) == "2")
real_id <- v$id [2] # = 3
expect_true (colnames (d2) == as.character (real_id))
expect_true (colnames (d3) == as.character (real_id))

graph <- data.frame (
from = as.character (c (1, 3, 2, 2, 3, 3, 4, 4)),
to = as.character (c (2, 1, 3, 4, 2, 4, 3, 1)),
d = c (1, 2, 1, 3, 2, 1, 2, 1)
)
d4 <- dodgr_dists (graph, from = "1", to = "2")
expect_equal (rownames (d4), "1")
expect_equal (colnames (d4), "2")

})

test_that ("to-from-cols", {
graph <- weight_streetnet (hampi)
nf <- 100
Expand Down

0 comments on commit 18532d8

Please sign in to comment.