Skip to content

Commit

Permalink
test: added tests for untested files (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics authored Feb 28, 2025
1 parent 3b04160 commit 0bac719
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 348 deletions.
389 changes: 347 additions & 42 deletions R/layout.R

Large diffs are not rendered by default.

304 changes: 0 additions & 304 deletions R/layout_drl.R

This file was deleted.

4 changes: 2 additions & 2 deletions R/minimum.spanning.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ mst <- function(graph, weights = NULL,
.Call(R_igraph_minimum_spanning_tree_unweighted, graph)
} else if (algorithm == "prim") {
if (is.null(weights) && !"weight" %in% edge_attr_names(graph)) {
stop("edges weights must be supplied for Prim's algorithm")
cli::cli_abort("edges weights must be supplied for Prim's algorithm.")
} else if (is.null(weights)) {
weights <- E(graph)$weight
}
on.exit(.Call(R_igraph_finalizer))
.Call(R_igraph_minimum_spanning_tree_prim, graph, as.numeric(weights))
} else {
stop("Invalid algorithm")
cli::cli_abort("Invalid {.arg algorithm}.")
}
}
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/minimum.spanning.tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# mst error works

Code
mst(g, algorithm = "undefined")
Condition
Error in `mst()`:
! Invalid `algorithm`.

28 changes: 28 additions & 0 deletions tests/testthat/test-centralization.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("centr_degree works", {
g <- make_star(5, "undirected")
g_centr <- centr_degree(g, normalized = FALSE)
g_centr_tmax <- centr_degree_tmax(g, loops = FALSE)
expect_equal(g_centr$centralization, g_centr_tmax)
})

test_that("centr_betw works", {
g <- make_star(5, "undirected")
g_centr <- centr_betw(g, normalized = FALSE)
g_centr_tmax <- centr_betw_tmax(g)
expect_equal(g_centr$centralization, g_centr_tmax)
})

test_that("centr_clo works", {
g <- make_star(5, "undirected")
g_centr <- centr_clo(g, normalized = FALSE)
g_centr_tmax <- centr_clo_tmax(g)
expect_equal(g_centr$centralization, g_centr_tmax)
})


test_that("centr_eigen works", {
g <- make_star(2, "undirected")
g_centr <- centr_eigen(g, normalized = FALSE)
g_centr_tmax <- centr_eigen_tmax(g)
expect_equal(g_centr$centralization, g_centr_tmax)
})
11 changes: 11 additions & 0 deletions tests/testthat/test-cocitation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("cocitation works", {
g <- make_full_graph(10, directed = TRUE)
cocite_mat <- matrix(8, 10, 10) - diag(8, 10)
expect_equal(cocitation(g), cocite_mat)
})

test_that("bibcoupling works", {
g <- make_full_graph(10, directed = TRUE)
bib_mat <- matrix(8, 10, 10) - diag(8, 10)
expect_equal(bibcoupling(g), bib_mat)
})
Loading

0 comments on commit 0bac719

Please sign in to comment.