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
56 changes: 28 additions & 28 deletions tests/testthat/test-aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -10890,11 +10890,11 @@ test_that("community_leading_eigenvector_callback_closure_impl basic", {

# Structured tests
expect_s3_class(result, "igraph.eigenc")
expect_true(is.list(result))
expect_type(result, "list")
expect_true("membership" %in% names(result))
expect_true("modularity" %in% names(result))
expect_true("merges" %in% names(result))
expect_equal(length(result$membership), vcount(g))
expect_length(result$membership, vcount(g))
expect_true(is.numeric(result$modularity))
})

Expand All @@ -10921,7 +10921,7 @@ test_that("community_leading_eigenvector_callback_closure_impl with start", {
})

expect_s3_class(result, "igraph.eigenc")
expect_equal(length(result$membership), vcount(g))
expect_length(result$membership, vcount(g))
})

test_that("community_leading_eigenvector_callback_closure_impl errors", {
Expand Down Expand Up @@ -11322,8 +11322,8 @@ test_that("dfs_closure_impl works", {
})

# Structured tests
expect_equal(length(dfs_in_visits), 10)
expect_equal(length(dfs_out_visits), 10)
expect_length(dfs_in_visits, 10)
expect_length(dfs_out_visits, 10)
})

# motifs_randesu_callback_closure_impl
Expand Down Expand Up @@ -11360,10 +11360,10 @@ test_that("motifs_randesu_callback_closure_impl basic", {
# Structured tests
expect_null(result)
expect_true(length(motif_data) > 0)
expect_true(is.integer(motif_data[[1]]$vids))
expect_equal(length(motif_data[[1]]$vids), 3)
expect_true(is.integer(motif_data[[1]]$isoclass))
expect_equal(length(motif_data[[1]]$isoclass), 1)
expect_type(motif_data[[1]]$vids, "integer")
expect_length(motif_data[[1]]$vids, 3)
expect_type(motif_data[[1]]$isoclass, "integer")
expect_length(motif_data[[1]]$isoclass, 1)
})

test_that("motifs_randesu_callback_closure_impl errors", {
Expand Down Expand Up @@ -11414,7 +11414,7 @@ test_that("cliques_callback_closure_impl basic", {
# Structured tests
expect_null(result)
expect_true(length(clique_data) > 0)
expect_true(is.integer(clique_data[[1]]))
expect_type(clique_data[[1]], "integer")
expect_true(length(clique_data[[1]]) >= 3)
expect_true(length(clique_data[[1]]) <= 4)
})
Expand Down Expand Up @@ -11471,7 +11471,7 @@ test_that("maximal_cliques_callback_closure_impl basic", {

# Structured tests
expect_null(result)
expect_true(is.integer(clique_data[[1]]))
expect_type(clique_data[[1]], "integer")
expect_true(length(clique_data[[1]]) >= 3)
})

Expand Down Expand Up @@ -11527,8 +11527,8 @@ test_that("simple_cycles_callback_closure_impl basic", {
# Structured tests
expect_null(result)
expect_true(length(cycle_data) > 0)
expect_true(is.integer(cycle_data[[1]]$vertices))
expect_true(is.integer(cycle_data[[1]]$edges))
expect_type(cycle_data[[1]]$vertices, "integer")
expect_type(cycle_data[[1]]$edges, "integer")
expect_equal(length(cycle_data[[1]]$vertices), length(cycle_data[[1]]$edges))
})

Expand Down Expand Up @@ -11591,10 +11591,10 @@ test_that("get_isomorphisms_vf2_callback_closure_impl basic", {
# Structured tests
expect_null(result)
expect_true(length(iso_data) > 0)
expect_true(is.integer(iso_data[[1]]$map12))
expect_true(is.integer(iso_data[[1]]$map21))
expect_equal(length(iso_data[[1]]$map12), vcount(g1))
expect_equal(length(iso_data[[1]]$map21), vcount(g2))
expect_type(iso_data[[1]]$map12, "integer")
expect_type(iso_data[[1]]$map21, "integer")
expect_length(iso_data[[1]]$map12, vcount(g1))
expect_length(iso_data[[1]]$map21, vcount(g2))
})

test_that("get_isomorphisms_vf2_callback_closure_impl errors", {
Expand Down Expand Up @@ -11659,10 +11659,10 @@ test_that("get_subisomorphisms_vf2_callback_closure_impl basic", {
# Structured tests
expect_null(result)
expect_true(length(subiso_data) > 0)
expect_true(is.integer(subiso_data[[1]]$map12))
expect_true(is.integer(subiso_data[[1]]$map21))
expect_equal(length(subiso_data[[1]]$map12), vcount(g1))
expect_equal(length(subiso_data[[1]]$map21), vcount(g2))
expect_type(subiso_data[[1]]$map12, "integer")
expect_type(subiso_data[[1]]$map21, "integer")
expect_length(subiso_data[[1]]$map12, vcount(g1))
expect_length(subiso_data[[1]]$map21, vcount(g2))
})

test_that("get_subisomorphisms_vf2_callback_closure_impl errors", {
Expand Down Expand Up @@ -11783,7 +11783,7 @@ test_that("sparse_weighted_adjacency_impl basic", {
expect_equal(vcount(g1), 4)
expect_equal(ecount(g1), 4)
expect_true(is_directed(g1))
expect_equal(length(weights), 4)
expect_length(weights, 4)
})

test_that("sparse_weighted_adjacency_impl errors", {
Expand Down Expand Up @@ -12038,8 +12038,8 @@ test_that("subisomorphic_lad_impl basic", {
# The function requires complex setup with pattern/target graphs and domains
# For now, just verify the function exists and has correct signature
expect_true(is.function(subisomorphic_lad_impl))
expect_equal(
names(formals(subisomorphic_lad_impl)),
expect_named(
formals(subisomorphic_lad_impl),
c("pattern", "target", "domains", "induced", "time_limit")
)
})
Expand Down Expand Up @@ -12076,8 +12076,8 @@ test_that("eigen_matrix_impl basic", {
# The function requires complex matrix setup and understanding of eigenvalue computation
# For now, just verify the function exists and has correct signature
expect_true(is.function(eigen_matrix_impl))
expect_equal(
names(formals(eigen_matrix_impl)),
expect_named(
formals(eigen_matrix_impl),
c("A", "sA", "fun", "n", "algorithm", "which", "options")
)
})
Expand Down Expand Up @@ -12106,8 +12106,8 @@ test_that("eigen_matrix_symmetric_impl basic", {
# The function requires complex matrix setup and understanding of eigenvalue computation
# For now, just verify the function exists and has correct signature
expect_true(is.function(eigen_matrix_symmetric_impl))
expect_equal(
names(formals(eigen_matrix_symmetric_impl)),
expect_named(
formals(eigen_matrix_symmetric_impl),
c("A", "sA", "fun", "n", "algorithm", "which", "options")
)
})
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ test_that("ivs() works, cliques of complement", {
},
cliques = cliques
)
expect_equal(sum(ivs_with_equivalent), length(ivs))
expect_length(ivs, sum(ivs_with_equivalent))

cliques_with_equivalent <- map_lgl(
cliques,
function(element, ivs) any(map_lgl(ivs, function(x) identical(x, element))),
ivs = ivs
)
expect_equal(sum(cliques_with_equivalent), length(cliques))
expect_length(cliques, sum(cliques_with_equivalent))
})

test_that("largest_cliques() works", {
Expand Down Expand Up @@ -386,7 +386,7 @@ test_that("cliques_callback receives correct arguments", {

# Check argument types
cliques(g, min = 3, max = 4, callback = function(clique) {
expect_true(is.integer(clique))
expect_type(clique, "integer")
expect_true(length(clique) >= 3)
expect_true(length(clique) <= 4)
FALSE # stop after first clique
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-coloring.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("greedy_vertex_coloring works on named graphs", {
V(g)$name <- LETTERS[1:vcount(g)]
vc <- greedy_vertex_coloring(g)
expect_equal(as.vector(vc), c(1, rep(2, vcount(g) - 1)))
expect_equal(names(vc), V(g)$name)
expect_named(vc, V(g)$name)
})

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

expect_equal(as.numeric(table(clu$membership)), clu$csize)
expect_equal(sort(clu$csize), sort(lg_size))
expect_equal(clu$no, length(random_lg_list))
expect_length(random_lg_list, clu$no)
})

test_that("components names results", {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ test_that("find_cycle() works", {
g <- make_graph(c(1, 2, 2, 3, 1, 3, 1, 1), directed = TRUE)

cycle <- find_cycle(g)
expect_equal(length(cycle$vertices), 1)
expect_equal(length(cycle$edges), 1)
expect_length(cycle$vertices, 1)
expect_length(cycle$edges, 1)

# Finding a cycle of length 1 or 3 are both valid here
cycle <- find_cycle(g, mode = "all")
expect_equal(length(cycle$vertices), 3)
expect_equal(length(cycle$edges), 3)
expect_length(cycle$vertices, 3)
expect_length(cycle$edges, 3)
})

test_that("simple_cycle() works directed", {
Expand Down Expand Up @@ -89,8 +89,8 @@ test_that("simple_cycles_callback receives correct arguments", {

# Check argument types
simple_cycles(g, callback = function(vertices, edges) {
expect_true(is.integer(vertices))
expect_true(is.integer(edges))
expect_type(vertices, "integer")
expect_type(edges, "integer")
expect_equal(length(vertices), length(edges))
expect_true(length(vertices) >= 1)
FALSE # stop after first cycle
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-decomposition.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ test_that("is_chordal works", {
)

ic <- is_chordal(g1, fillin = TRUE)
expect_equal(ic$chordal, FALSE)
expect_false(ic$chordal)
expect_equal(unique(sort(ic$fillin)), c(1, 2, 5, 6, 7, 8))
expect_equal(ic$newgraph, NULL)
expect_null(ic$newgraph)

g2 <- graph_from_literal(
A - B:E, B - A:E:F:D, C - E:D:G, D - B:F:E:C:G,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ test_that("min_st_separators works", {
g_zachary <- make_graph("Zachary")
msts <- min_st_separators(g_zachary)
is <- sapply(msts, is_separator, graph = g_zachary)
expect_equal(unique(is), TRUE)
expect_true(unique(is))

## TODO: check that it is minimal
})
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ test_that("Graphlets work for some simple graphs", {
E(full)$weight <- 1
full_glet <- graphlet_basis(full)

expect_equal(names(full_glet), c("cliques", "thresholds"))
expect_equal(length(full_glet$cliques), 1)
expect_named(full_glet, c("cliques", "thresholds"))
expect_length(full_glet$cliques, 1)
expect_equal(sort(full_glet$cliques[[1]]), V(full)[seq_len(vcount(full))])
expect_equal(full_glet$thresholds, 1)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test_that("[[ indexing works with filtering on both ends", {

test_that("[[ indexing is consistent with length()", {
g <- make_test_named_tree()
expect_equal(length(g), vcount(g))
expect_length(g, vcount(g))
})

test_that("[[ can query incident edges", {
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ test_that("vs/es keeps names after graph is deleted", {
rm(g)
gc()

expect_equal(names(vs), letters[1:10])
expect_named(vs, letters[1:10])

vs2 <- vs[4:7]
expect_equal(names(vs2), letters[4:7])
expect_named(vs2, letters[4:7])

expect_equal(names(es), LETTERS[1:10])
expect_named(es, LETTERS[1:10])

es2 <- es[4:7]
expect_equal(names(es2), LETTERS[4:7])
expect_named(es2, LETTERS[4:7])
})

test_that("both edge and vertex names", {
Expand All @@ -307,7 +307,7 @@ test_that("both edge and vertex names", {

es <- E(g)
expect_equal(as.vector(es), 1:10)
expect_equal(names(es), LETTERS[1:10])
expect_named(es, LETTERS[1:10])
el <- as_edgelist(g)
expect_equal(attr(es, "vnames"), paste(el[, 1], el[, 2], sep = "|"))

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-motifs.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ test_that("motifs with callback receives correct arguments", {

# Check argument types
motifs(g, 3, callback = function(vids, isoclass) {
expect_true(is.integer(vids))
expect_equal(length(vids), 3)
expect_true(is.integer(isoclass))
expect_equal(length(isoclass), 1)
expect_type(vids, "integer")
expect_length(vids, 3)
expect_type(isoclass, "integer")
expect_length(isoclass, 1)
TRUE # stop after first motif
})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-other.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ test_that("VS/ES work with old data type", {
karate2 <- upgrade_graph(karate)
vs2 <- V(karate2)

expect_equal(length(vs2), 34)
expect_length(vs2, 34)
expect_equal(vs2$name, names)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-par.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test_that("we can restore old options", {
annotate.plot = TRUE
)

expect_equal(igraph_opt("sparsematrices"), FALSE)
expect_equal(igraph_opt("annotate.plot"), TRUE)
expect_false(igraph_opt("sparsematrices"))
expect_true(igraph_opt("annotate.plot"))

igraph_options(old)

Expand All @@ -53,6 +53,6 @@ test_that("with_igraph_opt works", {
make_ring(3)[]
)

expect_equal(igraph_opt("sparsematrices"), TRUE)
expect_true(igraph_opt("sparsematrices"))
expect_true(inherits(res, "matrix"))
})
14 changes: 7 additions & 7 deletions tests/testthat/test-structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,17 @@ test_that("local transitivity() produces named vectors", {
g <- make_graph(~ a - b - c - a - d)
E(g)$weight <- 1:4
t1 <- transitivity(g, type = "local")
expect_equal(names(t1), V(g)$name)
expect_named(t1, V(g)$name)

t2 <- transitivity(g, type = "barrat")
expect_equal(names(t2), V(g)$name)
expect_named(t2, V(g)$name)

vs <- c("a", "c")
t3 <- transitivity(g, type = "local", vids = vs)
expect_equal(names(t3), vs)
expect_named(t3, vs)

t4 <- transitivity(g, type = "barrat", vids = vs)
expect_equal(names(t4), vs)
expect_named(t4, vs)
})

test_that("constraint() works", {
Expand Down Expand Up @@ -612,7 +612,7 @@ test_that("ego() works", {
#########

s <- ego_size(g, 2, v)[[1]]
expect_equal(s, length(v1))
expect_length(v1, s)
})

test_that("mindist works", {
Expand Down Expand Up @@ -1021,13 +1021,13 @@ test_that("knn works", {
expect_equal(r3$knn[43], 46)
expect_equal(r3$knn[1000], 192.4)
expect_equal(r3$knnk[100], 18.78)
expect_equal(length(r3$knnk), 359)
expect_length(r3$knnk, 359)

## A random graph
g4 <- sample_gnp(1000, p = 5 / 1000)
r4 <- knn(g4)
expect_equal(r4$knn[1000], 20 / 3)
expect_equal(length(r4$knnk), 15)
expect_length(r4$knnk, 15)
expect_equal(r4$knnk[12], 19 / 3)

## A weighted graph
Expand Down
Loading