Skip to content

Commit

Permalink
test: create and use expect_isomorphic()
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle authored and aviator-bot committed May 20, 2024
1 parent 0e75241 commit 4959fce
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 55 deletions.
4 changes: 4 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ expect_that <- function(object, condition, info = NULL, label = NULL) {
condition(object)
)
}

expect_isomorphic <- function(g1, g2) {
expect_true(graph.isomorphic(g1, g2))
}
8 changes: 4 additions & 4 deletions tests/testthat/test-as.directed.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ test_that("as.directed works", {
expect_that(degree(g), equals(degree(g4)))
expect_that(degree(g), equals(degree(g5)))

expect_true(graph.isomorphic(g, as.undirected(g2)))
expect_true(graph.isomorphic(g, as.undirected(g3)))
expect_true(graph.isomorphic(g, as.undirected(g4)))
expect_true(graph.isomorphic(g, as.undirected(g5)))
expect_isomorphic(g, as.undirected(g2))
expect_isomorphic(g, as.undirected(g3))
expect_isomorphic(g, as.undirected(g4))
expect_isomorphic(g, as.undirected(g5))
})

test_that("as.directed keeps attributes", {
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-ba.game.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("sample_pa can start from a graph", {
expect_true(sum(is_degree_two_or_three) %in% 0:4)

g6 <- sample_pa(10, m = 1, algorithm = "bag", start.graph = make_star(10))
expect_true(graph.isomorphic(g6, make_star(10)))
expect_isomorphic(g6, make_star(10))

g7 <- sample_pa(10,
m = 3, algorithm = "psumtree-multiple",
Expand All @@ -56,21 +56,21 @@ test_that("sample_pa can start from a graph", {
start.graph = make_star(5)
)
expect_that(degree(g8, mode = "out"), equals(c(0, 1, 1, 1, 1, 3, 3, 3, 3, 3)))
expect_true(graph.isomorphic(induced_subgraph(g8, 1:5), make_star(5)))
expect_isomorphic(induced_subgraph(g8, 1:5), make_star(5))

g9 <- sample_pa(10,
m = 3, algorithm = "psumtree-multiple",
start.graph = make_star(10)
)
expect_true(graph.isomorphic(g9, make_star(10)))
expect_isomorphic(g9, make_star(10))

g10 <- sample_pa(10, m = 3, start.graph = make_empty_graph(5))
expect_that(degree(g10, mode = "out"), equals(c(0, 0, 0, 0, 0, 3, 3, 3, 3, 3)))

g11 <- sample_pa(10, m = 3, start.graph = make_star(5))
expect_that(degree(g11, mode = "out"), equals(c(0, 1, 1, 1, 1, 3, 3, 3, 3, 3)))
expect_true(graph.isomorphic(induced_subgraph(g11, 1:5), make_star(5)))
expect_isomorphic(induced_subgraph(g11, 1:5), make_star(5))

g12 <- sample_pa(10, m = 3, start.graph = make_star(10))
expect_true(graph.isomorphic(g12, make_star(10)))
expect_isomorphic(g12, make_star(10))
})
8 changes: 4 additions & 4 deletions tests/testthat/test-bipartite.projection.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ test_that("bipartite_projection works", {

g <- make_full_bipartite_graph(10, 5)
proj <- bipartite_projection(g)
expect_true(graph.isomorphic(proj[[1]], make_full_graph(10)))
expect_true(graph.isomorphic(proj[[2]], make_full_graph(5)))
expect_isomorphic(proj[[1]], make_full_graph(10))
expect_isomorphic(proj[[2]], make_full_graph(5))

M <- matrix(0, nrow = 5, ncol = 3)
rownames(M) <- c("Alice", "Bob", "Cecil", "Dan", "Ethel")
Expand Down Expand Up @@ -47,8 +47,8 @@ test_that("bipartite_projection can calculate only one projection", {
proj1 <- bipartite_projection(g, which = "false")
proj2 <- bipartite_projection(g, which = "true")

expect_true(graph.isomorphic(proj$proj1, proj1))
expect_true(graph.isomorphic(proj$proj2, proj2))
expect_isomorphic(proj$proj1, proj1)
expect_isomorphic(proj$proj2, proj2)
expect_that(vertex.attributes(proj$proj1), equals(vertex.attributes(proj1)))
expect_that(vertex.attributes(proj$proj2), equals(vertex.attributes(proj2)))
expect_that(edge_attr(proj$proj1), equals(edge_attr(proj1)))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-delete.vertices.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ test_that("delete_vertices works", {
expect_equal(V(g2)$name, c("B", "C", "D", "E", "F"))

g3 <- delete_vertices(g, match("A", V(g)$name))
expect_true(graph.isomorphic(g2, g3))
expect_isomorphic(g2, g3)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-get.adjacency.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ test_that("as_adj works", {
g <- sample_gnp(50, 1 / 50)
A <- as_adj(g, sparse = FALSE)
g2 <- graph_from_adjacency_matrix(A, mode = "undirected")
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

###

A <- as_adj(g, sparse = TRUE)
g2 <- graph_from_adjacency_matrix(A, mode = "undirected")
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

###

g <- sample_gnp(50, 2 / 50, directed = TRUE)
A <- as_adj(g, sparse = FALSE)
g2 <- graph_from_adjacency_matrix(A)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

###

A <- as_adj(g, sparse = TRUE)
g2 <- graph_from_adjacency_matrix(A)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-get.adjlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("as_adj_list works", {
g <- sample_gnp(50, 2 / 50)
al <- as_adj_list(g)
g2 <- graph_from_adj_list(al, mode = "all")
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
expect_true(graph.isomorphic.vf2(g, g2,
vertex.color1 = 1:vcount(g),
vertex.color2 = 1:vcount(g2)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-get.edge.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ test_that("ends works", {
g <- sample_gnp(100, 3 / 100)
edges <- unlist(lapply(seq_len(ecount(g)), ends, graph = g))
g2 <- make_graph(edges, dir = FALSE, n = vcount(g))
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-get.edgelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ test_that("as_edgelist works", {
g <- sample_gnp(100, 3 / 100)
e <- as_edgelist(g)
g2 <- make_graph(t(e), n = vcount(g), dir = FALSE)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-graph.adjlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ test_that("graph_from_adj_list works", {
g <- sample_gnp(100, 3 / 100)
al <- as_adj_list(g)
g2 <- graph_from_adj_list(al, mode = "all")
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

##

g <- sample_gnp(100, 3 / 100, directed = TRUE)
al <- as_adj_list(g, mode = "out")
g2 <- graph_from_adj_list(al, mode = "out")
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
})
8 changes: 4 additions & 4 deletions tests/testthat/test-graph.atlas.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test_that("graph.atlas works", {
g124 <- graph_from_atlas(124)
expect_true(graph.isomorphic(g124, make_graph(c(1, 2, 2, 3, 3, 4, 4, 5, 1, 5, 1, 3, 2, 6),
expect_isomorphic(g124, make_graph(c(1, 2, 2, 3, 3, 4, 4, 5, 1, 5, 1, 3, 2, 6),
directed = FALSE
)))
))
g234 <- graph_from_atlas(234)
expect_true(graph.isomorphic(g234, make_graph(c(1, 6, 2, 6, 3, 6, 4, 6, 5, 6),
expect_isomorphic(g234, make_graph(c(1, 6, 2, 6, 3, 6, 4, 6, 5, 6),
n = 7,
directed = FALSE
)))
))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-graph.complementer.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ test_that("complementer works", {
g <- sample_gnp(50, 3 / 50)
g2 <- complementer(g)
g3 <- complementer(g2)
expect_true(graph.isomorphic(g, g3))
expect_isomorphic(g, g3)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-graph.compose.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ test_that("compose works", {
g2 <- compose(g1, gi)
g3 <- compose(gi, g1)

expect_true(graph.isomorphic(g1, g2))
expect_true(graph.isomorphic(g1, g3))
expect_isomorphic(g1, g2)
expect_isomorphic(g1, g3)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-graph.de.bruijn.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ test_that("make_de_bruijn_graph works", {
g2 <- make_de_bruijn_graph(2, 2)
g3 <- make_line_graph(g)

expect_true(graph.isomorphic(g3, make_graph(c(
expect_isomorphic(g3, make_graph(c(
1, 1, 3, 1, 1, 2, 3, 2, 2, 3,
4, 3, 2, 4, 4, 4
))))
expect_true(graph.isomorphic(g2, g3))
)))
expect_isomorphic(g2, g3)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-graph.edgelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ test_that("graph_from_edgelist works", {
g <- sample_gnp(50, 5 / 50)
el <- as_edgelist(g)
g2 <- graph_from_edgelist(el, directed = FALSE)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

####

g <- sample_gnp(50, 5 / 50, directed = TRUE)
el <- as_edgelist(g)
g2 <- graph_from_edgelist(el, directed = TRUE)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)

####

Expand All @@ -22,5 +22,5 @@ test_that("graph_from_edgelist works", {
mode(el) <- "character"
el[] <- n[el]
g2 <- graph_from_edgelist(el, directed = TRUE)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-graphNEL.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("graphNEL conversion works", {

N <- as_graphnel(g)
g2 <- graph_from_graphnel(N)
expect_true(graph.isomorphic(g, g2))
expect_isomorphic(g, g2)
expect_that(V(g)$name, equals(V(g2)$name))

A <- as_adj(g, attr = "weight", sparse = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-neighborhood.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("ego works", {
v <- sample(vcount(g), 1)
g1 <- make_ego_graph(g, 2, v)[[1]]
g2 <- neig(g, 2, v)
expect_true(graph.isomorphic(g1, g2))
expect_isomorphic(g1, g2)

#########

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ test_that("operators work", {

####

expect_true(graph.isomorphic(difference(gu, g1), g2))
expect_isomorphic(difference(gu, g1), g2)

####

expect_true(graph.isomorphic(intersection(gu, g2), g2))
expect_isomorphic(intersection(gu, g2), g2)

expect_true(graph.isomorphic(
expect_isomorphic(
intersection(gu, g1,
keep.all.vertices = FALSE
),
g1
))
)

####

Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-operators3.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ test_that("infix operators work", {
g <- g - c("a", "b")
expect_that(vcount(g), equals(8))
expect_that(ecount(g), equals(7))
expect_true(graph.isomorphic(g, make_lattice(8)))
expect_isomorphic(g, make_lattice(8))

g <- g - edge("e|f")
expect_true(graph.isomorphic(g, make_lattice(5) + make_lattice(3)))
expect_isomorphic(g, make_lattice(5) + make_lattice(3))

g <- g - edge("H")
expect_true(graph.isomorphic(g, graph_from_literal(a - b - c, d - e - f, g - h)))
expect_isomorphic(g, graph_from_literal(a - b - c, d - e - f, g - h))

g <- make_ring(10)
V(g)$name <- letters[1:10]
g <- g - path("a", "b")
expect_true(graph.isomorphic(g, graph_from_literal(a, b - c - d - e - f - g - h - i - j - a)))
expect_isomorphic(g, graph_from_literal(a, b - c - d - e - f - g - h - i - j - a))
g <- g + path("a", "b")
expect_true(graph.isomorphic(g, make_ring(10)))
expect_isomorphic(g, make_ring(10))

g <- make_ring(10)
V(g)$name <- letters[1:10]

g <- g - path("a", "b", "c", "d")
expect_true(graph.isomorphic(g, make_lattice(8) + 2))
expect_isomorphic(g, make_lattice(8) + 2)

expect_true(graph.isomorphic(
expect_isomorphic(
g - V(g)[c("d", "g")],
make_lattice(4) + make_lattice(2) + 2
))
)

expect_true(graph.isomorphic(
expect_isomorphic(
g - E(g)["f" %--% "g"],
make_lattice(5) + make_lattice(3) + 2
))
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-sbm.game.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("Generating stochastic block models works", {
pref.matrix = pm, block.sizes = bs,
directed = FALSE, loops = FALSE
)
expect_true(graph.isomorphic(g1, make_full_graph(10, directed = FALSE, loops = FALSE)))
expect_isomorphic(g1, make_full_graph(10, directed = FALSE, loops = FALSE))

g2 <- sample_sbm(10,
pref.matrix = pm, block.sizes = bs,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-unfold.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ test_that("unfold_tree works", {
g <- make_tree(7, 2)
g <- add_edges(g, c(2, 7, 1, 4))
g2 <- unfold_tree(g, roots = 1)
expect_true(graph.isomorphic(g2$tree, make_graph(c(
expect_isomorphic(g2$tree, make_graph(c(
1, 2, 1, 3, 2, 8, 2, 5, 3, 6,
3, 9, 2, 7, 1, 4
))))
)))
expect_that(g2$vertex_index, equals(c(1, 2, 3, 4, 5, 6, 7, 4, 7)))
})

0 comments on commit 4959fce

Please sign in to comment.