Skip to content

Commit 8a8c6e3

Browse files
committed
test: add tests for as_adjacency_matrix
1 parent 36d92f9 commit 8a8c6e3

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# as_adjacency_matrix() works
2+
3+
Code
4+
as_adjacency_matrix(example_graph, sparse = TRUE)
5+
Output
6+
2 x 2 sparse Matrix of class "dgCMatrix"
7+
8+
[1,] 1 1
9+
[2,] 1 .
10+

tests/testthat/test-conversion.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_that("as_adjacency_matrix() works", {
2+
# https://github.com/igraph/rigraph/issues/1429
3+
a_matrix <- (matrix(sample(rep(c(0,1),8)), nrow = 4, ncol = 4))
4+
ig <- graph_from_adjacency_matrix(a_matrix, mode = "directed")
5+
b_matrix <- as_adjacency_matrix(ig, sparse = FALSE)
6+
expect_identical(diag(a_matrix), diag(b_matrix))
7+
8+
expect_identical(
9+
as_adjacency_matrix(make_graph(c(1,1)), sparse = FALSE),
10+
matrix(1)
11+
)
12+
13+
example_graph <- make_graph(c(1,1, 1,2), directed = FALSE)
14+
expect_identical(
15+
as_adjacency_matrix(example_graph, sparse = FALSE),
16+
matrix(c(1, 1, 1, 0), nrow = 2, ncol = 2)
17+
)
18+
expect_snapshot(
19+
as_adjacency_matrix(example_graph, sparse = TRUE)
20+
)
21+
})

0 commit comments

Comments
 (0)