Skip to content

Commit 9b034b3

Browse files
committed
tests: k_shortest_paths()
1 parent 2bfb80a commit 9b034b3

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test_that("k_shortest_paths works", {
2+
g <- make_ring(5)
3+
res <- k_shortest_paths(g, 1, 2, k = 3)
4+
expect_length(res$vpaths, 2)
5+
expect_length(res$epaths, 2)
6+
expect_equal(as.numeric(res$vpaths[[1]]), c(1, 2))
7+
expect_equal(as.numeric(res$epaths[[1]]), c(1))
8+
expect_equal(as.numeric(res$vpaths[[2]]), c(1, 5, 4, 3, 2))
9+
expect_equal(as.numeric(res$epaths[[2]]), c(5, 4, 3, 2))
10+
})
11+
12+
test_that("k_shortest_paths works with weights", {
13+
g <- make_graph(c(1,2, 1,3, 3,2))
14+
E(g)$weight <- c(5, 2, 1)
15+
res <- k_shortest_paths(g, 1, 2, k = 3)
16+
expect_length(res$vpaths, 2)
17+
expect_length(res$epaths, 2)
18+
expect_equal(as.numeric(res$vpaths[[1]]), c(1, 3, 2))
19+
expect_equal(as.numeric(res$epaths[[1]]), c(2, 3))
20+
expect_equal(as.numeric(res$vpaths[[2]]), c(1, 2))
21+
expect_equal(as.numeric(res$epaths[[2]]), c(1))
22+
})

0 commit comments

Comments
 (0)