From d287845486a2ab4e9a450db99cc72ad42d0deb57 Mon Sep 17 00:00:00 2001 From: Cesaire Joris Kuete Fouodo Date: Fri, 19 Jul 2024 07:44:43 +0200 Subject: [PATCH] eightedMeanLearner: 100% test coverage --- .covrignore | 1 - R/weightedMeanLearner.R | 6 ++--- tests/testthat/test-weightedMeanLearner.R | 27 +++++++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.covrignore b/.covrignore index f7af7e3..6497a0e 100644 --- a/.covrignore +++ b/.covrignore @@ -15,4 +15,3 @@ ./R/TrainMetaLayer.R ./R/TrainStudy.R ./R/VarSel.R -./R/weightedMeanLearner.R diff --git a/R/weightedMeanLearner.R b/R/weightedMeanLearner.R index a30dd95..55c3887 100644 --- a/R/weightedMeanLearner.R +++ b/R/weightedMeanLearner.R @@ -14,9 +14,9 @@ #' @export #' #' @examples -#' set.seed(20240624) -#' x = data.frame(x1 = rnorm(50)) -#' y = sample(x = 0:1, size = 50, replace = TRUE) +#' set.seed(20240624L) +#' x = data.frame(x1 = rnorm(50L)) +#' y = sample(x = 0L:1L, size = 50L, replace = TRUE) #' my_model = weightedMeanLearner(x = x, y = y) #' weightedMeanLearner = function (x, y) { diff --git a/tests/testthat/test-weightedMeanLearner.R b/tests/testthat/test-weightedMeanLearner.R index 8849056..9cc541b 100644 --- a/tests/testthat/test-weightedMeanLearner.R +++ b/tests/testthat/test-weightedMeanLearner.R @@ -1,3 +1,26 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) +test_that("weightedMeanLearner works", { + expect_no_error({ + set.seed(20240624L) + x = data.frame(x1 = rnorm(50L)) + y = sample(x = 0L:1L, size = 50L, replace = TRUE) + my_model = weightedMeanLearner(x = x, y = y) + }) + expect_error({ + set.seed(20240624L) + x = data.frame(x1 = rnorm(50L)) + y = sample(x = 0L:2L, size = 50L, replace = TRUE) + my_model = weightedMeanLearner(x = x, y = y) + }) + expect_no_error({ + set.seed(20240624L) + x = data.frame(x1 = rnorm(50L)) + y = sample(x = c("control", "case"), size = 50L, replace = TRUE) + my_model = weightedMeanLearner(x = x, y = y) + }) + expect_no_error({ + set.seed(20240624L) + x = data.frame(x1 = rnorm(50L)) + y = sample(x = c("0", "1"), size = 50L, replace = TRUE) + my_model = weightedMeanLearner(x = x, y = factor(y)) + }) })