Skip to content

Commit

Permalink
test: fold sample_bipartite() tests into test-games
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 13, 2024
1 parent b29c853 commit 7c32e76
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 133 deletions.
18 changes: 0 additions & 18 deletions tests/testthat/_snaps/bipartite.random.game.md

This file was deleted.

18 changes: 18 additions & 0 deletions tests/testthat/_snaps/games.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@
Error in `sample_degseq()`:
! At vendor/cigraph/src/games/degree_sequence_vl/gengraph_mr-connected.cpp:<linenumber> : Cannot realize the given degree sequence as an undirected, simple graph. Invalid value

# sample_bipartite() deprecation

Code
s <- sample_bipartite(10, 5, type = "gnp", p = 0)
Condition
Warning:
`sample_bipartite()` was deprecated in igraph 2.1.3.
i Please use `sample_bipartite_gnp()` instead.

---

Code
s <- sample_bipartite(10, 5, type = "gnm", m = 0)
Condition
Warning:
`sample_bipartite()` was deprecated in igraph 2.1.3.
i Please use `sample_bipartite_gnm()` instead.

115 changes: 0 additions & 115 deletions tests/testthat/test-bipartite.random.game.R

This file was deleted.

115 changes: 115 additions & 0 deletions tests/testthat/test-games.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,118 @@ test_that("sample_pa can start from a graph", {
expect_isomorphic(g12, make_star(10))
})

test_that("sample_bipartite() works", {
rlang::local_options(lifecycle_verbosity = "quiet")
withr::local_seed(42)
g1 <- sample_bipartite(10, 5, type = "gnp", p = .1)
expect_equal(g1$name, "Bipartite Gnp random graph")
expect_equal(vcount(g1), 15)
expect_equal(ecount(g1), 7)
expect_true(bipartite_mapping(g1)$res)
expect_false(is_directed(g1))

g2 <- sample_bipartite(10, 5, type = "gnp", p = .1, directed = TRUE)
expect_equal(vcount(g2), 15)
expect_equal(ecount(g2), 6)
expect_true(bipartite_mapping(g2)$res)
expect_true(is_directed(g2))
expect_output(print_all(g2), "5->11")

g3 <- sample_bipartite(10, 5, type = "gnp", p = .1, directed = TRUE, mode = "in")
expect_output(print_all(g3), "11->3")

g4 <- sample_bipartite(10, 5, type = "gnm", m = 8)
expect_equal(vcount(g4), 15)
expect_equal(ecount(g4), 8)
expect_true(bipartite_mapping(g4)$res)
expect_false(is_directed(g4))

g5 <- sample_bipartite(10, 5, type = "gnm", m = 8, directed = TRUE)
expect_equal(vcount(g5), 15)
expect_equal(ecount(g5), 8)
expect_true(bipartite_mapping(g5)$res)
expect_true(is_directed(g5))
expect_output(print_all(g5), "5->12")

g6 <- sample_bipartite(10, 5, type = "gnm", m = 8, directed = TRUE, mode = "in")
expect_equal(vcount(g6), 15)
expect_equal(ecount(g6), 8)
expect_true(bipartite_mapping(g6)$res)
expect_true(is_directed(g6))
expect_output(print_all(g6), "12->10")

#####

g7 <- sample_bipartite(10, 5,
type = "gnp", p = 0.9999, directed = TRUE,
mode = "all"
)
expect_equal(ecount(g7), 100)

g8 <- sample_bipartite(10, 5,
type = "gnm", m = 99, directed = TRUE,
mode = "all"
)
expect_equal(ecount(g8), 99)
})

test_that("sample_bipartite() deprecation", {
expect_snapshot(s <- sample_bipartite(10, 5, type = "gnp", p = 0))
expect_snapshot(s <- sample_bipartite(10, 5, type = "gnm", m = 0))
})

test_that("sample_bipartite_gnp() works", {
withr::local_seed(42)
g1 <- sample_bipartite_gnp(10, 5, p = .1)
expect_equal(g1$name, "Bipartite Gnp random graph")
expect_equal(vcount(g1), 15)
expect_equal(ecount(g1), 7)
expect_true(bipartite_mapping(g1)$res)
expect_false(is_directed(g1))

g2 <- sample_bipartite_gnp(10, 5, p = .1, directed = TRUE)
expect_equal(vcount(g2), 15)
expect_equal(ecount(g2), 6)
expect_true(bipartite_mapping(g2)$res)
expect_true(is_directed(g2))
expect_output(print_all(g2), "5->11")

g3 <- sample_bipartite_gnp(10, 5, p = .1, directed = TRUE, mode = "in")
expect_output(print_all(g3), "11->3")

g7 <- sample_bipartite_gnp(10, 5,
p = 0.9999, directed = TRUE,
mode = "all"
)
expect_equal(ecount(g7), 100)

})
test_that("sample_bipartite_gnm() works", {
withr::local_seed(42)

g4 <- sample_bipartite_gnm(10, 5, m = 8)
expect_equal(vcount(g4), 15)
expect_equal(ecount(g4), 8)
expect_true(bipartite_mapping(g4)$res)
expect_false(is_directed(g4))

g5 <- sample_bipartite_gnm(10, 5, m = 8, directed = TRUE)
expect_equal(vcount(g5), 15)
expect_equal(ecount(g5), 8)
expect_true(bipartite_mapping(g5)$res)
expect_true(is_directed(g5))
expect_output(print_all(g5), "5->11 7->11 8->11 8->12 4->13 5->13 6->13 9->13")

g6 <- sample_bipartite_gnm(10, 5, m = 8, directed = TRUE, mode = "in")
expect_equal(vcount(g6), 15)
expect_equal(ecount(g6), 8)
expect_true(bipartite_mapping(g6)$res)
expect_true(is_directed(g6))
expect_output(print_all(g6), "11-> 4 11-> 5 12-> 7 12-> 8 12-> 9 14-> 6 14->10 15-> 4")

g8 <- sample_bipartite_gnm(10, 5,
m = 99, directed = TRUE,
mode = "all"
)
expect_equal(ecount(g8), 99)
})

0 comments on commit 7c32e76

Please sign in to comment.