From 13355e0a95f8ccd91a15e3d8439a2cda73b7a6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Sat, 3 Feb 2024 18:23:35 +0000 Subject: [PATCH] test: distances() --- tests/testthat/test-distances.R | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/testthat/test-distances.R diff --git a/tests/testthat/test-distances.R b/tests/testthat/test-distances.R new file mode 100644 index 0000000000..c8a5b81d5c --- /dev/null +++ b/tests/testthat/test-distances.R @@ -0,0 +1,37 @@ +test_that("distances works", { + g <- make_graph(c(1, 5, 1, 7, 1, 8, 1, 10, 2, 6, + 2, 7, 2, 8, 2, 10, 3, 4, 3, 5, + 3, 9, 5, 6, 5, 7, 5, 10, 6, 8, + 7, 8, 7, 9, 8, 9, 8, 10, 9, 10), + directed = FALSE) + + mu <- distances(g, algorithm = "unweighted") + + # unit weights + E(g)$weight <- rep(1, ecount(g)) + + ma <- distances(g) # automatic + md <- distances(g, algorithm = "dijkstra") + mbf <- distances(g, algorithm = "bellman-ford") + mj <- distances(g, algorithm = "johnson") + mfw <- distances(g, algorithm = "floyd-warshall") + + expect_equal(mu, ma) + expect_equal(mu, md) + expect_equal(mu, mbf) + expect_equal(mu, mj) + expect_equal(mu, mfw) + + E(g)$weight <- 0.25 * (1:ecount(g)) + + ma <- distances(g) # automatic + md <- distances(g, algorithm = "dijkstra") + mbf <- distances(g, algorithm = "bellman-ford") + mj <- distances(g, algorithm = "johnson") + mfw <- distances(g, algorithm = "floyd-warshall") + + expect_equal(ma, md) + expect_equal(ma, mbf) + expect_equal(ma, mj) + expect_equal(ma, mfw) +})