Skip to content

Commit

Permalink
test: add tests for feedback_arc_set() and feedback_vertex_set()
Browse files Browse the repository at this point in the history
  • Loading branch information
szhorvat committed Oct 22, 2024
1 parent 9896898 commit c735a09
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/testthat/test-feedback-sets.R
Original file line number Diff line number Diff line change
@@ -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))
})

0 comments on commit c735a09

Please sign in to comment.