tests/testthat/test-print_igraph.R

test_that("str.igraph prints without error and includes key sections", {
    library(igraph)
    set.seed(1)
    g <- sample_gnp(8, 0.4, directed = TRUE)
    g$name <- "test net"
    V(g)$grp <- rep(1:2, 4)
    E(g)$weight <- seq_len(ecount(g))
    out <- paste(capture.output(str(g)), collapse = "\n")
    expect_true(grepl("TEST NET", out))
    expect_true(grepl("directed", out))
    expect_true(grepl("weighted", out))
    expect_true(grepl("Nodes: 8", out))
    expect_true(grepl("Graph Attributes", out))
    expect_true(grepl("Vertex Attributes", out))
    expect_true(grepl("Edge Attributes", out))
})

test_that("str.igraph handles a minimal graph with no attributes or edges", {
    library(igraph)
    g <- make_empty_graph(n = 3, directed = FALSE)
    out <- paste(capture.output(str(g)), collapse = "\n")
    expect_true(grepl("UNNAMED NETWORK", out))
    expect_true(grepl("Edges: 0", out))
    expect_true(grepl("Isolates: 3", out))
})

Try the netUtils package in your browser

Any scripts or data that you put into this service are public.

netUtils documentation built on June 13, 2026, 1:06 a.m.