From ac70c467988adada78af006692ba46faf705c80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Wed, 19 Feb 2025 17:42:13 +0100 Subject: [PATCH 1/3] feat: hrg functions check their argument --- R/hrg.R | 13 ++++++++++++- tests/testthat/_snaps/hrg.md | 16 ++++++++++++++++ tests/testthat/test-hrg.R | 13 +++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/R/hrg.R b/R/hrg.R index 9fb2bc0e6f5..015cc2715c8 100644 --- a/R/hrg.R +++ b/R/hrg.R @@ -287,6 +287,11 @@ hrg <- hrg_create_impl #' @export #' @cdocs igraph_from_hrg_dendrogram hrg_tree <- function(hrg) { + + if (!inherits(hrg, "igraphHRG")) { + cli::cli_abort("{.arg hrg} must be a {.cls igraphHRG} object, not {.obj_type_friendly {hrg}}.") + } + out <- from_hrg_dendrogram_impl(hrg) g <- out$graph @@ -305,8 +310,14 @@ hrg_tree <- function(hrg) { #' @family hierarchical random graph functions #' @export #' @cdocs igraph_hrg_game -sample_hrg <- hrg_game_impl +sample_hrg <- function(hrg) { + if (!inherits(hrg, "igraphHRG")) { + cli::cli_abort("{.arg hrg} must be a {.cls igraphHRG} object, not {.obj_type_friendly {hrg}}.") + } + + hrg_game_impl(hrg) +} #' Predict edges based on a hierarchical random graph model #' #' `predict_edges()` uses a hierarchical random graph model to predict diff --git a/tests/testthat/_snaps/hrg.md b/tests/testthat/_snaps/hrg.md index 8dd969e9d26..3f29cb77335 100644 --- a/tests/testthat/_snaps/hrg.md +++ b/tests/testthat/_snaps/hrg.md @@ -11,3 +11,19 @@ method 1 -none- character dist.method 1 -none- character +# sample_hrg() checks its argument + + Code + sample_hrg(make_ring(10)) + Condition + Error in `sample_hrg()`: + ! `hrg` must be a object, not an object. + +# hrg_tree() checks its argument + + Code + hrg_tree(make_ring(10)) + Condition + Error in `hrg_tree()`: + ! `hrg` must be a object, not an object. + diff --git a/tests/testthat/test-hrg.R b/tests/testthat/test-hrg.R index c584be3d63c..1262bbb77e5 100644 --- a/tests/testthat/test-hrg.R +++ b/tests/testthat/test-hrg.R @@ -16,3 +16,16 @@ test_that("as.hclust.igraphHRG() works", { summary(as.hclust(hrg)) }) }) + +test_that("sample_hrg() checks its argument", { + expect_snapshot(error = TRUE, { + sample_hrg(make_ring(10)) + }) +}) + + +test_that("hrg_tree() checks its argument", { + expect_snapshot(error = TRUE, { + hrg_tree(make_ring(10)) + }) +}) From 11cdc948d0a0a06d0153f2a52d00c6b0ba9431cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 20 Feb 2025 10:16:59 +0100 Subject: [PATCH 2/3] a -> an --- tests/testthat/_snaps/hrg.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/hrg.md b/tests/testthat/_snaps/hrg.md index 3f29cb77335..239f5400186 100644 --- a/tests/testthat/_snaps/hrg.md +++ b/tests/testthat/_snaps/hrg.md @@ -17,7 +17,7 @@ sample_hrg(make_ring(10)) Condition Error in `sample_hrg()`: - ! `hrg` must be a object, not an object. + ! `hrg` must be an object, not an object. # hrg_tree() checks its argument @@ -25,5 +25,5 @@ hrg_tree(make_ring(10)) Condition Error in `hrg_tree()`: - ! `hrg` must be a object, not an object. + ! `hrg` must be an object, not an object. From 7c8fe6892ba43db4b7dff1e1e1a28dbfc02900d0 Mon Sep 17 00:00:00 2001 From: maelle <8360597+maelle@users.noreply.github.com> Date: Thu, 20 Feb 2025 09:21:56 +0000 Subject: [PATCH 3/3] [create-pull-request] automated change --- tests/testthat/_snaps/hrg.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/hrg.md b/tests/testthat/_snaps/hrg.md index 239f5400186..3f29cb77335 100644 --- a/tests/testthat/_snaps/hrg.md +++ b/tests/testthat/_snaps/hrg.md @@ -17,7 +17,7 @@ sample_hrg(make_ring(10)) Condition Error in `sample_hrg()`: - ! `hrg` must be an object, not an object. + ! `hrg` must be a object, not an object. # hrg_tree() checks its argument @@ -25,5 +25,5 @@ hrg_tree(make_ring(10)) Condition Error in `hrg_tree()`: - ! `hrg` must be an object, not an object. + ! `hrg` must be a object, not an object.