From 369f86355950900ed81ceac999394480374ac7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Mon, 21 Oct 2024 20:21:07 +0000 Subject: [PATCH] test: add tests for `feedback_arc_set()` and `feedback_vertex_set()` --- tests/testthat/test-feedback-sets.R | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/testthat/test-feedback-sets.R diff --git a/tests/testthat/test-feedback-sets.R b/tests/testthat/test-feedback-sets.R new file mode 100644 index 0000000000..3f80757c92 --- /dev/null +++ b/tests/testthat/test-feedback-sets.R @@ -0,0 +1,41 @@ +test_that("feedback_arc_set works", { + skip_if_no_glpk() + + g <- make_graph(c(1,2, 2,3, 3,1, 4,2, 3,4), directed = TRUE) + fas <- feedback_arc_set(g) + expect_equal(as.vector(fas), c(2)) +}) + +test_that("feedback_arc_set works with weights", { + skip_if_no_glpk() + + g <- make_ring(4, directed = TRUE) + E(g)$weight <- 4:1 + fas <- feedback_arc_set(g) + expect_equal(as.vector(fas), c(4)) +}) + +test_that("feedback_arc_set works with undirected graphs", { + skip_if_no_glpk() + + g <- make_ring(10) + fas <- feedback_arc_set(g) + expect_equal(length(fas), 1) +}) + +test_that("feedback_vertex_set works", { + skip_if_no_glpk() + + g <- make_lattice(c(3, 3)) + fvs <- feedback_vertex_set(g) + expect_equal(length(fvs), 2) +}) + +test_that("feedback_vertex_set works with weights", { + skip_if_no_glpk() + + g <- make_ring(5, directed = TRUE) + V(g)$weight <- 5:1 + fvs <- feedback_vertex_set(g) + expect_equal(as.vector(fvs), c(5)) +})