|
| 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