-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathtest-utils.R
More file actions
32 lines (24 loc) · 1.07 KB
/
test-utils.R
File metadata and controls
32 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
test_that("functions work as expected without warnings", {
expect_equal(min_na(NA), NA)
expect_equal(max_na(NA), NA)
})
test_that("get_feature_names() work with '.' features", {
fit_rf <- randomForest::randomForest(Sepal.Width ~ ., data = iris)
fit_ranger <- ranger::ranger(Sepal.Width ~ ., data = iris)
expected <- setdiff(colnames(iris), "Sepal.Width")
expect_equal(get_feature_names(fit_rf), expected)
expect_equal(get_feature_names(fit_ranger), expected)
})
test_that("get_feature_names() work with explicit features", {
form <- Sepal.Width ~ Sepal.Length + Species
fit_rf <- randomForest::randomForest(form, data = iris)
fit_ranger <- ranger::ranger(form, data = iris)
expected <- c("Sepal.Length", "Species")
expect_equal(get_feature_names(fit_rf), expected)
expect_equal(get_feature_names(fit_ranger), expected)
})
test_that("get_feature_names() work with xy interface of ranger", {
xvars <- setdiff(colnames(iris), "Sepal.Width")
fit_ranger <- ranger::ranger(y = iris$Sepal.Width, x = iris[xvars])
expect_equal(get_feature_names(fit_ranger), xvars)
})