Skip to content

Commit

Permalink
add tests for #201
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed May 8, 2023
1 parent 1931051 commit a673d45
Show file tree
Hide file tree
Showing 3 changed files with 32 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.2.20.018
Version: 0.2.20.019
Authors@R: c(
person("Mark", "Padgham", , "mark.padgham@email.com", 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 @@ -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.20.018",
"version": "0.2.20.019",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-dists-categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,36 @@ test_that ("categorical dists", {
expect_identical (d, d2)
})

test_that ("categorical dists results", {

net <- weight_streetnet (hampi, wt_profile = "foot")
v <- dodgr_vertices (net)
set.seed (1L)
from <- sample (v$id, 20)
to <- sample (v$id, 20)

net$edge_type <- net$highway
d0 <- dodgr_dists_categorical (net, from, to, proportions_only = FALSE, pairwise = FALSE)
# Sums of all "type" matrices should equal main "distances" matrix:
types <- which (names (d0) != "distances")
d_types <- lapply (types, function (i) colSums (d0 [[i]]))
d_types <- colSums (do.call (rbind, d_types))
d_total <- colSums (d0$distances)
expect_true (all (abs (d_total - d_types) < 1e-6))

d1 <- dodgr_dists_categorical (net, from, to, proportions_only = FALSE, pairwise = TRUE)
index_rows <- which (d1 [, 1] > 0)
index_cols <- which (colnames (d1) != "total")
d_total <- d1 [index_rows, 1L]
d_types <- rowSums (d1 [index_rows, index_cols])
expect_true (all (abs (d_total - d_types) < 1e-6))

p0 <- dodgr_dists_categorical (net, from, to, proportions_only = TRUE)
dp <- vapply (d0, function (i) sum (colSums (i)), numeric (1L))
p1 <- dp [-1] / dp [1]
expect_true (all (abs (p0 - p1) < 1e-6))
})

test_that ("categorical dists summary", {

expect_silent (graph <- weight_streetnet (hampi))
Expand Down

0 comments on commit a673d45

Please sign in to comment.