Skip to content

Commit

Permalink
converted error tests to snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Feb 13, 2025
1 parent f3ab2c5 commit ce6cb74
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 14 deletions.
98 changes: 98 additions & 0 deletions tests/testthat/_snaps/flow.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,101 @@
# st_cuts errors work

Code
st_cuts(g_path, source = "a", target = NULL)
Condition
Error in `st_cuts()`:
! No vertex was specified

---

Code
st_cuts(g_path, source = NULL, target = "a")
Condition
Error in `st_cuts()`:
! No vertex was specified

---

Code
st_min_cuts(g_path, source = "a", target = NULL)
Condition
Error in `st_min_cuts()`:
! No vertex was specified

---

Code
st_min_cuts(g_path, source = NULL, target = "a")
Condition
Error in `st_min_cuts()`:
! No vertex was specified

# vertex_connectivity error works

Code
vertex_connectivity(g_path, source = 1)
Condition
Error in `vertex_connectivity()`:
! `source` and `target` must not be specified at the same time.
i Specify either `source` or `target` or neither.

# edge_connectivity error works

Code
edge_connectivity(g_path, source = 1)
Condition
Error in `edge_connectivity()`:
! `source` and `target` must not be specified at the same time.
i Specify either `source` or `target` or neither.

# edge_disjoint_paths error works

Code
edge_disjoint_paths(g_path, source = 1, target = NULL)
Condition
Error in `edge_disjoint_paths()`:
! Both source and target must be given

---

Code
edge_disjoint_paths(g_path, source = NULL, target = 1)
Condition
Error in `edge_disjoint_paths()`:
! Both source and target must be given

# vertex_disjoint_paths error works

Code
vertex_disjoint_paths(g_path, source = 1)
Condition
Error in `vertex_disjoint_paths()`:
! Both source and target must be given

---

Code
vertex_disjoint_paths(g_path, source = 1)
Condition
Error in `vertex_disjoint_paths()`:
! Both source and target must be given

# dominator_tree errors work

Code
dominator_tree(g_tree)
Condition
Error in `dominator_tree()`:
! argument "root" is missing, with no default

---

Code
dominator_tree(g_tree, root = NULL)
Condition
Error in `dominator_tree()`:
! `root` must be specified.

# min_st_separators() works for the note case

Code
Expand Down
40 changes: 26 additions & 14 deletions tests/testthat/test-flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ test_that("st_cuts() works", {

g_star_v7 <- graph_from_literal(s - +a:b - +t, a - +1:2:3 - +b)
all_cuts_star_v7 <- st_cuts(g_star_v7, source = "s", target = "t")
expect_equal(unvs(all_cuts_star_v7$cuts), list(c(1, 2), c(1, 7), c(2, 3, 4, 5, 6), c(2, 3, 4, 5, 10), c(2, 3, 4, 6, 9), c(2, 3, 4, 9, 10), c(2, 3, 5, 6, 8), c(2, 3, 5, 8, 10), c(2, 3, 6, 8, 9), c(2, 3, 8, 9, 10), c(3, 7)))
expect_equal(
unvs(all_cuts_star_v7$cuts),
list(
c(1, 2), c(1, 7), c(2, 3, 4, 5, 6), c(2, 3, 4, 5, 10),
c(2, 3, 4, 6, 9), c(2, 3, 4, 9, 10), c(2, 3, 5, 6, 8),
c(2, 3, 5, 8, 10), c(2, 3, 6, 8, 9), c(2, 3, 8, 9, 10), c(3, 7)
)
)
expect_equal(
unvs(all_cuts_star_v7$partition1s),
list(1, c(1, 3), c(1, 2), c(1, 2, 7), c(1, 2, 6), c(1, 2, 6, 7), c(1, 2, 5), c(1, 2, 5, 7), c(1, 2, 5, 6), c(1, 2, 5, 6, 7), c(1, 2, 5, 6, 7, 3))
list(
1, c(1, 3), c(1, 2), c(1, 2, 7), c(1, 2, 6),
c(1, 2, 6, 7), c(1, 2, 5), c(1, 2, 5, 7),
c(1, 2, 5, 6), c(1, 2, 5, 6, 7), c(1, 2, 5, 6, 7, 3)
)
)

g_star_v9 <- graph_from_literal(s - +a:b - +t, a - +1:2:3:4:5 - +b)
Expand All @@ -67,10 +78,11 @@ test_that("st_cuts() works", {

test_that("st_cuts errors work", {
g_path <- graph_from_literal(a - +b - +c - +d - +e)
expect_error(st_cuts(g_path, source = "a", target = NULL))
expect_error(st_cuts(g_path, source = NULL, target = "a"))
expect_error(st_min_cuts(g_path, source = "a", target = NULL))
expect_error(st_min_cuts(g_path, source = NULL, target = "a"))

expect_snapshot(st_cuts(g_path, source = "a", target = NULL), error = TRUE)
expect_snapshot(st_cuts(g_path, source = NULL, target = "a"), error = TRUE)
expect_snapshot(st_min_cuts(g_path, source = "a", target = NULL), error = TRUE)
expect_snapshot(st_min_cuts(g_path, source = NULL, target = "a"), error = TRUE)
})

test_that("max_flow works", {
Expand Down Expand Up @@ -98,7 +110,7 @@ test_that("vertex_connectivity() works", {

test_that("vertex_connectivity error works", {
g_path <- make_ring(5, circular = FALSE)
expect_error(vertex_connectivity(g_path, source = 1))
expect_snapshot(vertex_connectivity(g_path, source = 1), error = TRUE)
})

test_that("edge_connectivity works", {
Expand Down Expand Up @@ -136,7 +148,7 @@ test_that("edge_connectivity works -- names", {

test_that("edge_connectivity error works", {
g_path <- make_ring(5, circular = FALSE)
expect_error(edge_connectivity(g_path, source = 1))
expect_snapshot(edge_connectivity(g_path, source = 1), error = TRUE)
})

test_that("edge_disjoint_paths works", {
Expand All @@ -149,8 +161,8 @@ test_that("edge_disjoint_paths works", {

test_that("edge_disjoint_paths error works", {
g_path <- make_ring(5, circular = FALSE)
expect_error(edge_disjoint_paths(g_path, source = 1, target = NULL))
expect_error(edge_disjoint_paths(g_path, source = NULL, target = 1))
expect_snapshot(edge_disjoint_paths(g_path, source = 1, target = NULL), error = TRUE)
expect_snapshot(edge_disjoint_paths(g_path, source = NULL, target = 1), error = TRUE)
})

test_that("vertex_disjoint_paths works", {
Expand All @@ -163,7 +175,7 @@ test_that("vertex_disjoint_paths works", {

test_that("vertex_disjoint_paths error works", {
g_path <- make_ring(5, circular = FALSE)
expect_error(vertex_disjoint_paths(g_path, source = 1))
expect_snapshot(vertex_disjoint_paths(g_path, source = 1), error = TRUE)
})

test_that("adhesion works", {
Expand All @@ -176,7 +188,7 @@ test_that("adhesion works", {

test_that("vertex_disjoint_paths error works", {
g_path <- make_ring(5, circular = FALSE)
expect_error(vertex_disjoint_paths(g_path, source = 1))
expect_snapshot(vertex_disjoint_paths(g_path, source = 1), error = TRUE)
})


Expand All @@ -197,8 +209,8 @@ test_that("dominator_tree works", {

test_that("dominator_tree errors work", {
g_tree <- graph_from_edgelist(matrix(c(1, 2, 2, 3, 3, 4, 2, 5, 5, 6), byrow = TRUE, ncol = 2), directed = TRUE)
expect_error(dominator_tree(g_tree))
expect_error(dominator_tree(g_tree, root = NULL))
expect_snapshot(dominator_tree(g_tree), error = TRUE)
expect_snapshot(dominator_tree(g_tree, root = NULL), error = TRUE)
})

test_that("dominator_tree works -- legacy", {
Expand Down

0 comments on commit ce6cb74

Please sign in to comment.