Skip to content

Commit

Permalink
add most tests for fortify.igraph
Browse files Browse the repository at this point in the history
  • Loading branch information
briatte committed Jul 27, 2019
1 parent 0bba28b commit a286424
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test-ggnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ test_that("ggnetwork works", {
expect_error(ggnetwork(-999, "could not coerce"))
expect_error(ggnetwork(emon[[1]], layout = -999, "unsupported layout"))

# with igraph
n <- igraph::graph_from_adjacency_matrix(as.matrix(emon[[1]]))
igraph::E(n)$Frequency <- network::get.edge.attribute(emon[[1]], "Frequency")

# facet by edge attribute
expect_s3_class({
ggnetwork(emon[[1]], arrow.gap = 0.02, by = "Frequency")
}, class = "data.frame")
# with igraph
expect_s3_class({
ggnetwork(n, arrow.gap = 0.02, by = "Frequency")
}, class = "data.frame")

# user-provided layout
expect_s3_class({
ggnetwork(emon[[1]], layout = matrix(runif(28), ncol = 2))
}, class = "data.frame")
# with igraph
expect_s3_class({
ggnetwork(n, layout = matrix(runif(28), ncol = 2))
}, class = "data.frame")

# edge weights in layout
expect_s3_class({
ggnetwork(emon[[1]], layout = "kamadakawai", weights = "Frequency")
}, class = "data.frame")
# with igraph
expect_s3_class({
ggnetwork(n, layout = igraph::with_kk(weights = igraph::E(n)$Frequency))
}, class = "data.frame")

# duplicated edges warning
expect_warning(
Expand Down

0 comments on commit a286424

Please sign in to comment.