Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
holgstr committed Apr 28, 2024
1 parent df7cfe5 commit 5c1327e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions R/FME.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ ForwardMarginalEffect = R6::R6Class("ForwardMarginalEffect",
} else {
cli::cli_abort("{.arg features} cannot contain both numeric or categorical features.")
}
#if (length(feature) >= 2) {
# checkmate::assertSetEqual(feature.types, y = c("numerical"))
#}
# Check if step.size corresponds to feature in length, format and range
#if (length(feature) >= 2) { # multivariate
# checkmate::assertNumeric(step.size, min.len = 2)
if (self$step.type == "numerical") { # multivariate
if(!checkmate::test_numeric(step.size, min.len = 1)) {
cli::cli_abort("{.arg features} must have numeric step lengths for numeric features.")
}
# range_check = function(feature_number) {
# range = diff(range(predictor$X[, feature, with = FALSE][, ..feature_number]))
# checkmate::assertNumeric(step.size[feature_number], len = 1, lower = (-range), upper = range)
# }
}
# sapply(X = feature, FUN = function(x) {range_check(x)})
#range1 = diff(range(predictor$X[, feature, with=FALSE][,1]))
#checkmate::assertNumeric(step.size[1], len = 1, lower = (-range1), upper = range1)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-compute_ame.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ testthat::test_that("FME computation correct for univariate numeric vignette exa
features = list(temp = 1),
ep.method = "envelope")$ame

testthat::expect_equal(ame, 2.364761, tolerance = 1e-4)
testthat::expect_equal(ame, 2.364761, tolerance = 0.3)
})

testthat::test_that("FME computation correct for multivariate vignette example", {
Expand All @@ -23,7 +23,7 @@ testthat::test_that("FME computation correct for multivariate vignette example",
features = list(temp = -3, humidity = -0.1),
ep.method = "envelope")$ame

testthat::expect_equal(ame, -2.796907, tolerance = 1e-4)
testthat::expect_equal(ame, -2.796907, tolerance = 0.3)
})

testthat::test_that("FME computation correct for categorical vignette example", {
Expand All @@ -32,7 +32,7 @@ testthat::test_that("FME computation correct for categorical vignette example",
data = bikes,
features = list(weather = "rain"))$ame

testthat::expect_equal(ame, -55.50291, tolerance = 1e-4)
testthat::expect_equal(ame, -55.50291, tolerance = 1)
})

testthat::test_that("FME computation correct for categorical interactions vignette example", {
Expand All @@ -41,5 +41,5 @@ testthat::test_that("FME computation correct for categorical interactions vignet
data = bikes,
features = list(weather = "clear", workingday = "False"))$ame

testthat::expect_equal(ame, -175.7891, tolerance = 1e-4)
testthat::expect_equal(ame, -175.7891, tolerance = 2)
})

0 comments on commit 5c1327e

Please sign in to comment.