Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/community.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# modularity_matrix no longer accepts a membership argument for compatibility

Code
x <- modularity_matrix(karate, membership = rep(1, vcount(karate)))
modularity_matrix(karate, membership = rep(1, vcount(karate)))
Condition
Error:
! The `membership` argument of `modularity_matrix()` is no longer used as of igraph 2.1.0.
Expand Down
11 changes: 3 additions & 8 deletions tests/testthat/_snaps/foreign.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,15 @@
# graph_from_graphdb works

Code
g <- graph_from_graphdb(nodes = 1000)

---

Code
g <- graph_from_graphdb()
graph_from_graphdb()
Condition
Error in `graph_from_graphdb()`:
! Either `nodes`' or ``url`' must be non-null.

---

Code
g <- graph_from_graphdb(nodes = 10, prefix = "not_existing")
graph_from_graphdb(nodes = 10, prefix = "not_existing")
Condition
Error in `graph_from_graphdb()`:
! not_existing is not a valid prefix.
Expand All @@ -67,7 +62,7 @@
---

Code
g <- graph_from_graphdb(nodes = 10, type = "not_existing")
graph_from_graphdb(nodes = 10, type = "not_existing")
Condition
Error in `graph_from_graphdb()`:
! not_existing is not a valid graph type.
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/incidence.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# graph_from_biadjacency_matrix() errors well

Code
(g <- graph_from_biadjacency_matrix(inc, weight = FALSE))
(graph_from_biadjacency_matrix(inc, weight = FALSE))
Condition
Error in `graph_from_biadjacency_matrix()`:
! `weighted` can't be `FALSE`.
Expand All @@ -70,7 +70,7 @@
---

Code
(g <- graph_from_biadjacency_matrix(inc, weight = 42))
(graph_from_biadjacency_matrix(inc, weight = 42))
Condition
Error in `graph_from_biadjacency_matrix()`:
! `weighted` can't be a number.
Expand All @@ -79,7 +79,7 @@
---

Code
(g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE))
(graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE))
Condition
Error in `graph_from_biadjacency_matrix()`:
! `multiple` and `weighted` cannot be both `TRUE`.
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ test_that("bracketing works (not changing attribute of similar graphs)", {
g <- make_graph(c(1, 2, 1, 3, 3, 4))

g <- set_vertex_attr(g, name = "weight", value = 1:vcount(g))
# jarl-ignore unused_object: test design
graph2 <- set_vertex_attr(g, name = "weight", value = rep(1, vcount(g)))
expect_equal(vertex_attr(g, name = "weight"), 1:4)

g <- set_edge_attr(g, name = "weight", value = 1:ecount(g))
# jarl-ignore unused_object: test design
graph2 <- set_edge_attr(g, name = "weight", value = rep(1, ecount(g)))
expect_equal(edge_attr(g, name = "weight"), 1:3)

g <- set_graph_attr(g, name = "name", "foo")
# jarl-ignore unused_object: test design
graph2 <- set_graph_attr(g, name = "name", "foobar")
expect_equal(graph_attr(g, name = "name"), "foo")
})
Expand All @@ -33,10 +36,12 @@ test_that("bracketing works with a function (not changing attribute of similar g

copy_test <- function(g) {
graph2 <- set_vertex_attr(g, name = "weight", value = rep(1, vcount(g)))
graph2 <- set_edge_attr(g, name = "weight", value = rep(1, ecount(g)))
graph2 <- set_graph_attr(g, name = "name", "foobar")
graph2 <- set_edge_attr(graph2, name = "weight", value = rep(1, ecount(g)))
graph2 <- set_graph_attr(graph2, name = "name", "foobar")
graph2
}

# jarl-ignore unused_object: test design
g2 <- copy_test(g)
expect_equal(vertex_attr(g, name = "weight"), 1:4)
expect_equal(edge_attr(g, name = "weight"), 1:3)
Expand All @@ -56,6 +61,7 @@ test_that("bracketing works with shortcuts (not changing attribute of similar gr
graph$name <- "foobar"
}

# jarl-ignore unused_object: test design
g_copy <- copy_test(g)
expect_equal(vertex_attr(g, name = "weight"), 1:4)
expect_equal(edge_attr(g, name = "weight"), 1:3)
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ test_that("undirected alpha_centrality() works, #653", {
expect_equal(ac1, ac2)

g2 <- as_directed(g, mode = "mutual")
ac3 <- alpha_centrality(g, sparse = FALSE)
ac3 <- alpha_centrality(g2, sparse = FALSE)
expect_equal(ac1, ac3)
})

Expand Down Expand Up @@ -776,11 +776,12 @@ test_that("spectrum() works for symmetric matrices", {

rlang::local_options(lifecycle_verbosity = "warning")
expect_warning(
e3 <- spectrum(
spectrum(
g,
which = list(howmany = 4, pos = "SA"),
options = arpack_defaults
)
),
"must be a list"
)
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-community.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ test_that("cluster_leading_eigen works", {
multiplier(v)
})
ev <- eigen(M)
ret <- 0

expect_equal(ev$values[1], value)
if (sign(ev$vectors[1, 1]) != sign(vector[1])) {
ev$vectors <- -ev$vectors
Expand Down Expand Up @@ -284,7 +284,7 @@ test_that("cluster_leading_eigen works", {
A <- as_adjacency_matrix(karate, sparse = FALSE)
ec <- ecount(karate)
deg <- degree(karate)
karate_lc2 <- cluster_leading_eigen(karate, callback = mod_mat_caller)
cluster_leading_eigen(karate, callback = mod_mat_caller)
})

test_that("cluster_leading_eigen is deterministic", {
Expand Down Expand Up @@ -474,7 +474,7 @@ test_that("modularity_matrix works", {
test_that("modularity_matrix no longer accepts a membership argument for compatibility", {
karate <- make_graph("zachary")
expect_snapshot(error = TRUE, {
x <- modularity_matrix(karate, membership = rep(1, vcount(karate)))
modularity_matrix(karate, membership = rep(1, vcount(karate)))
})
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ test_that("graphNEL conversion works", {

A <- as_adjacency_matrix(g, weights = "weight", sparse = FALSE)
A2 <- as_adjacency_matrix(g2, weights = "weight", sparse = FALSE)
expect_equal(A, A)
expect_equal(A, A2)
expect_equal(g$name, g2$name)
})

Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ test_that("simple_cycle() works directed", {
})

test_that("simple_cycle() works undirected", {
g <- graph_from_literal(A -+ B -+ C -+ A -+ D -+ E +- F -+ A, E -+ E, A -+ F, simplify = FALSE)
g <- graph_from_literal(
A -+ B -+ C -+ A -+ D -+ E +- F -+ A, E -+ E, A -+ F,
simplify = FALSE
)
all_simple_cycles <- simple_cycles(g, mode = "all")
expect_length(all_simple_cycles$vertices, 5)
expect_length(all_simple_cycles$edges, 5)
Expand All @@ -40,8 +43,8 @@ test_that("simple_cycle() works undirected", {
expect_equal(as.numeric(all_simple_cycles$vertices[[2]]), c(1, 4, 5, 6))

all_simple_cycles_23 <- simple_cycles(g, mode = "all", min = 2, max = 3)
expect_length(all_simple_cycles$vertices, 5)
expect_length(all_simple_cycles$edges, 5)
expect_length(all_simple_cycles_23$vertices, 2)
expect_length(all_simple_cycles_23$edges, 2)
})

# Tests for callback function
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-foreign.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ test_that("graph_from_graphdb works", {
# docker run --rm -ti -v $PWD:/rigraph -e MAKEFLAGS=-j4 ghcr.io/cynkra/docker-images/rigraph-san:latest RDcsan -q -e 'filename <- "/rigraph/DESCRIPTION"; gz_file_con <- file(filename, open = "rb"); file_con <- gzcon(gz_file_con); close(file_con); gc()'
skip_if(Sys.getenv("R_SANITIZER") == "true")

expect_snapshot(g <- graph_from_graphdb(nodes = 1000))
expect_snapshot_igraph_error(g <- graph_from_graphdb())
expect_silent(graph_from_graphdb(nodes = 1000))
expect_snapshot_igraph_error(graph_from_graphdb())
expect_snapshot_igraph_error(
g <- graph_from_graphdb(nodes = 10, prefix = "not_existing")
graph_from_graphdb(nodes = 10, prefix = "not_existing")
)
expect_snapshot_igraph_error(
g <- graph_from_graphdb(nodes = 10, type = "not_existing")
graph_from_graphdb(nodes = 10, type = "not_existing")
)
})
1 change: 0 additions & 1 deletion tests/testthat/test-glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ test_that("Graphlets filtering works", {
})

threshold.net <- function(graph, level) {
N <- vcount(graph)
graph.t <- delete_edges(graph, which(E(graph)$weight < level))

clqt <- unvs(max_cliques(graph.t))
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ test_that("graph_from_biadjacency_matrix() errors well", {
rownames(inc) <- LETTERS[1:3]

expect_snapshot_igraph_error({
(g <- graph_from_biadjacency_matrix(inc, weight = FALSE))
(graph_from_biadjacency_matrix(inc, weight = FALSE))
})
expect_snapshot_igraph_error({
(g <- graph_from_biadjacency_matrix(inc, weight = 42))
(graph_from_biadjacency_matrix(inc, weight = 42))
})
expect_snapshot_igraph_error({
(g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE))
(graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE))
})
})

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ test_that("[[ queries edges with vertex names", {
)
})
test_that("[ handles from and to properly", {
g <- make_test_named_tree()

g <- make_tree(20)
expect_equal(g[from = c(1, 2, 2, 3), to = c(3, 4, 8, 7)], c(1, 1, 0, 1))

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ test_that("vs/es refers to the original graph", {
vs <- V(ring1)
es <- E(ring1)

# jarl-ignore unused_object: test design
ring1 <- ring1 + 4

expect_identical(get_vs_graph(vs), ring2)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ test_that("parameters are evaluated early", {

cc <- 5
spec <- as_star(center = cc)
cc <- 10
l2 <- layout_(g, spec)
expect_identical(l1, l2)
})
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-make.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ test_that("make_de_bruijn_graph works", {

test_that("make_bipartite_graph works", {
inc_mat_rand <- matrix(sample(0:1, 35, replace = TRUE, prob = c(3, 1)), ncol = 5)
bip_from_inc <- graph_from_biadjacency_matrix(inc_mat_rand)

edges <- unlist(sapply(seq_len(nrow(inc_mat_rand)), function(x) {
w <- which(inc_mat_rand[x, ] != 0) + nrow(inc_mat_rand)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-palette.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ test_that("r_pal() works correctly", {
test_that("r_pal() handles edge cases", {
# Warning for too many colors (note: message says "divergent" - this might be a bug!)
expect_warning(
result <- r_pal(15),
r_pal(15),
"Cannot make 15 divergent colors" # This warning message seems wrong
)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-random_walk.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test_that("directed random_walk works", {
expect_equal(w2, c(4:1, 10:9))

w3 <- as_ids(random_walk(g, start = 1, steps = 5, mode = "all"))
expect_length(w, 6)
expect_true(all(abs(diff(as.numeric(w))) %in% c(1, 9)))
expect_length(w3, 6)
expect_true(all(abs(diff(as.numeric(w3))) %in% c(1, 9)))
})

test_that("directed random_walk can return wtih an error when stuck", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ test_that("ego() works", {
neig <- function(graph, order, vertices) {
sp <- distances(graph)
v <- unique(unlist(lapply(vertices, function(x) {
w <- which(sp[x, ] <= order)
which(sp[x, ] <= order)
})))
induced_subgraph(graph, c(v, vertices))
}
Expand All @@ -607,7 +607,7 @@ test_that("ego() works", {
nei <- function(graph, order, vertices) {
sp <- distances(graph)
v <- unique(unlist(lapply(vertices, function(x) {
w <- which(sp[x, ] <= order)
which(sp[x, ] <= order)
})))
v
}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-weakref.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test_that("weak reference finalizer is called", {
value <- "foobar"
hello <- ""
fin <- function(env) hello <<- "world"
# jarl-ignore unused_object: test design
vs <- make_weak_ref(key = g, value = value, finalizer = fin)

rm(g)
Expand Down
Loading