Skip to content

Commit

Permalink
eightedMeanLearner: 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fouodo committed Jul 19, 2024
1 parent fdbf4ab commit d287845
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 0 additions & 1 deletion .covrignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
./R/TrainMetaLayer.R
./R/TrainStudy.R
./R/VarSel.R
./R/weightedMeanLearner.R
6 changes: 3 additions & 3 deletions R/weightedMeanLearner.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 25 additions & 2 deletions tests/testthat/test-weightedMeanLearner.R
Original file line number Diff line number Diff line change
@@ -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))
})
})

0 comments on commit d287845

Please sign in to comment.