Skip to content
Merged
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
8 changes: 4 additions & 4 deletions R/other.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ running_mean <- function(v, binwidth) {
v <- as.numeric(v)
binwidth <- as.numeric(binwidth)
if (length(v) < binwidth) {
stop("Vector too short for this binwidth.")
cli::cli_abort("Vector too short for this binwidth.")
}

on.exit(.Call(R_igraph_finalizer))
Expand Down Expand Up @@ -127,7 +127,7 @@ running_mean <- function(v, binwidth) {
#'
sample_seq <- function(low, high, length) {
if (length > high - low + 1) {
stop("length too big for this interval")
cli::cli_abort("length too big for this interval")
}

on.exit(.Call(R_igraph_finalizer))
Expand Down Expand Up @@ -165,11 +165,11 @@ handle_vertex_type_arg <- function(types, graph, required = T) {
}
types <- as.logical(types)
if (any(is.na(types))) {
stop("`NA' is not allowed in vertex types")
cli::cli_abort("`NA' is not allowed in vertex types")
}
}
if (is.null(types) && required) {
stop("Not a bipartite graph, supply `types' argument or add a vertex attribute named `type'")
cli::cli_abort("Not a bipartite graph, supply {.arg types} argument or add a vertex attribute named {.arg type}.")
}
return(types)
}
Expand Down
9 changes: 0 additions & 9 deletions tests/testthat/_snaps/old-data-type.md

This file was deleted.

34 changes: 34 additions & 0 deletions tests/testthat/_snaps/other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# running_mean works

Code
running_mean(1:3, 4)
Condition
Error in `running_mean()`:
! Vector too short for this binwidth.

# serialization works

Code
g
Output
IGRAPH D--- 3 3 -- Ring graph
+ attr: name (g/c), mutual (g/l), circular (g/l)
+ edges:
[1] 1->2 2->3 3->1
Code
gs
Output
IGRAPH D--- 3 3 -- Ring graph
+ attr: name (g/c), mutual (g/l), circular (g/l)
+ edges:
[1] 1->2 2->3 3->1

# VS/ES require explicit conversion

Code
V(karate)
Condition
Error in `warn_version()`:
! This graph was created by a now unsupported old igraph version.
Call upgrade_graph() before using igraph functions on that object.

17 changes: 0 additions & 17 deletions tests/testthat/_snaps/serialize.md

This file was deleted.

14 changes: 0 additions & 14 deletions tests/testthat/test-convex_hull.R

This file was deleted.

10 changes: 0 additions & 10 deletions tests/testthat/test-handler.R

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
test_that("convex_hull works", {
xy <- cbind(c(0, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2), c(0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2))
vp <- convex_hull(xy)
expect_equal(vp$resverts, c(1, 6, 10, 11, 5))
expect_equal(vp$rescoords, xy[vp$resverts, ])
})

test_that("convex_hull uses 1-based indexing, #613", {
withr::local_seed(45)
n <- 10
xy <- cbind(runif(n), runif(n))
vp <- convex_hull(xy)
expect_equal(vp$resverts, c(8, 10, 7, 2, 1))
})

test_that("can create graphs when igraph is not attached", {
g <- callr::r(function() {
igraph::make_ring(3, directed = TRUE)
})
g2 <- make_ring(3, directed = TRUE)
expect_identical(
unclass(g)[-igraph_t_idx_env],
unclass(g2)[-igraph_t_idx_env]
)
})

test_that("running_mean works", {
expect_equal(running_mean(1:10, 2), 2:10 - 0.5)
expect_snapshot(
running_mean(1:3, 4),
error = TRUE
)
})

test_that("R help contains guarantee on number of RNG bits", {
skip_on_cran()

# utils:::.getHelpFile
get_help_file <- get(".getHelpFile", envir = asNamespace("utils"))
text <- capture.output(tools::Rd2txt(get_help_file(help("Random"))))

expect_true(any(grepl("all give at least 30 varying bits", text, fixed = TRUE)))
})

test_that("serialization works", {
local_igraph_options(print.id = FALSE)

g <- make_ring(3, directed = TRUE)
gs <- unserialize(serialize(g, NULL))

expect_identical(unclass(g)[-igraph_t_idx_env], unclass(gs)[-igraph_t_idx_env])

expect_snapshot({
g
gs
})
})

names <- c(
"Mr Hi", "Actor 2", "Actor 3", "Actor 4",
"Actor 5", "Actor 6", "Actor 7", "Actor 8", "Actor 9", "Actor 10",
Expand Down
9 changes: 0 additions & 9 deletions tests/testthat/test-rng.R

This file was deleted.

13 changes: 0 additions & 13 deletions tests/testthat/test-serialize.R

This file was deleted.