Skip to content

Commit 4959fce

Browse files
maelleaviator-bot
authored andcommitted
test: create and use expect_isomorphic()
1 parent 0e75241 commit 4959fce

21 files changed

+59
-55
lines changed

tests/testthat/helper.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ expect_that <- function(object, condition, info = NULL, label = NULL) {
2525
condition(object)
2626
)
2727
}
28+
29+
expect_isomorphic <- function(g1, g2) {
30+
expect_true(graph.isomorphic(g1, g2))
31+
}

tests/testthat/test-as.directed.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ test_that("as.directed works", {
1010
expect_that(degree(g), equals(degree(g4)))
1111
expect_that(degree(g), equals(degree(g5)))
1212

13-
expect_true(graph.isomorphic(g, as.undirected(g2)))
14-
expect_true(graph.isomorphic(g, as.undirected(g3)))
15-
expect_true(graph.isomorphic(g, as.undirected(g4)))
16-
expect_true(graph.isomorphic(g, as.undirected(g5)))
13+
expect_isomorphic(g, as.undirected(g2))
14+
expect_isomorphic(g, as.undirected(g3))
15+
expect_isomorphic(g, as.undirected(g4))
16+
expect_isomorphic(g, as.undirected(g5))
1717
})
1818

1919
test_that("as.directed keeps attributes", {

tests/testthat/test-ba.game.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_that("sample_pa can start from a graph", {
4343
expect_true(sum(is_degree_two_or_three) %in% 0:4)
4444

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

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

6161
g9 <- sample_pa(10,
6262
m = 3, algorithm = "psumtree-multiple",
6363
start.graph = make_star(10)
6464
)
65-
expect_true(graph.isomorphic(g9, make_star(10)))
65+
expect_isomorphic(g9, make_star(10))
6666

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

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

7474
g12 <- sample_pa(10, m = 3, start.graph = make_star(10))
75-
expect_true(graph.isomorphic(g12, make_star(10)))
75+
expect_isomorphic(g12, make_star(10))
7676
})

tests/testthat/test-bipartite.projection.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ test_that("bipartite_projection works", {
44

55
g <- make_full_bipartite_graph(10, 5)
66
proj <- bipartite_projection(g)
7-
expect_true(graph.isomorphic(proj[[1]], make_full_graph(10)))
8-
expect_true(graph.isomorphic(proj[[2]], make_full_graph(5)))
7+
expect_isomorphic(proj[[1]], make_full_graph(10))
8+
expect_isomorphic(proj[[2]], make_full_graph(5))
99

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

50-
expect_true(graph.isomorphic(proj$proj1, proj1))
51-
expect_true(graph.isomorphic(proj$proj2, proj2))
50+
expect_isomorphic(proj$proj1, proj1)
51+
expect_isomorphic(proj$proj2, proj2)
5252
expect_that(vertex.attributes(proj$proj1), equals(vertex.attributes(proj1)))
5353
expect_that(vertex.attributes(proj$proj2), equals(vertex.attributes(proj2)))
5454
expect_that(edge_attr(proj$proj1), equals(edge_attr(proj1)))

tests/testthat/test-delete.vertices.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ test_that("delete_vertices works", {
55
expect_equal(V(g2)$name, c("B", "C", "D", "E", "F"))
66

77
g3 <- delete_vertices(g, match("A", V(g)$name))
8-
expect_true(graph.isomorphic(g2, g3))
8+
expect_isomorphic(g2, g3)
99
})

tests/testthat/test-get.adjacency.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ test_that("as_adj works", {
22
g <- sample_gnp(50, 1 / 50)
33
A <- as_adj(g, sparse = FALSE)
44
g2 <- graph_from_adjacency_matrix(A, mode = "undirected")
5-
expect_true(graph.isomorphic(g, g2))
5+
expect_isomorphic(g, g2)
66

77
###
88

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

1313
###
1414

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

2020
###
2121

2222
A <- as_adj(g, sparse = TRUE)
2323
g2 <- graph_from_adjacency_matrix(A)
24-
expect_true(graph.isomorphic(g, g2))
24+
expect_isomorphic(g, g2)
2525
})

tests/testthat/test-get.adjlist.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ test_that("as_adj_list works", {
22
g <- sample_gnp(50, 2 / 50)
33
al <- as_adj_list(g)
44
g2 <- graph_from_adj_list(al, mode = "all")
5-
expect_true(graph.isomorphic(g, g2))
5+
expect_isomorphic(g, g2)
66
expect_true(graph.isomorphic.vf2(g, g2,
77
vertex.color1 = 1:vcount(g),
88
vertex.color2 = 1:vcount(g2)

tests/testthat/test-get.edge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ test_that("ends works", {
22
g <- sample_gnp(100, 3 / 100)
33
edges <- unlist(lapply(seq_len(ecount(g)), ends, graph = g))
44
g2 <- make_graph(edges, dir = FALSE, n = vcount(g))
5-
expect_true(graph.isomorphic(g, g2))
5+
expect_isomorphic(g, g2)
66
})

tests/testthat/test-get.edgelist.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ test_that("as_edgelist works", {
22
g <- sample_gnp(100, 3 / 100)
33
e <- as_edgelist(g)
44
g2 <- make_graph(t(e), n = vcount(g), dir = FALSE)
5-
expect_true(graph.isomorphic(g, g2))
5+
expect_isomorphic(g, g2)
66
})

tests/testthat/test-graph.adjlist.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ test_that("graph_from_adj_list works", {
22
g <- sample_gnp(100, 3 / 100)
33
al <- as_adj_list(g)
44
g2 <- graph_from_adj_list(al, mode = "all")
5-
expect_true(graph.isomorphic(g, g2))
5+
expect_isomorphic(g, g2)
66

77
##
88

99
g <- sample_gnp(100, 3 / 100, directed = TRUE)
1010
al <- as_adj_list(g, mode = "out")
1111
g2 <- graph_from_adj_list(al, mode = "out")
12-
expect_true(graph.isomorphic(g, g2))
12+
expect_isomorphic(g, g2)
1313
})

0 commit comments

Comments
 (0)