Skip to content

Commit 48d9d19

Browse files
committed
test basic adjust_numeric_range() usage
1 parent 4eac902 commit 48d9d19

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/testthat/test-adjust-numeric-range.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
test_that("basic adjust_numeric_range() usage works", {
2+
library(tibble)
3+
4+
# create example data
5+
set.seed(1)
6+
d <- tibble(y = rnorm(100), y_pred = y/2 + rnorm(100))
7+
8+
# fitting and predicting happens without raising conditions
9+
expect_no_condition(
10+
tlr <-
11+
tailor() %>%
12+
adjust_numeric_range(lower_limit = 1, upper_limit = 2)
13+
)
14+
15+
expect_no_condition(
16+
tlr_fit <- fit(tlr, d, outcome = y, estimate = y_pred)
17+
)
18+
19+
expect_no_condition(
20+
tlr_pred <- predict(tlr_fit, d)
21+
)
22+
23+
# classes are as expected
24+
expect_s3_class(tlr, "tailor")
25+
expect_s3_class(tlr_fit, "tailor")
26+
expect_s3_class(tlr_pred, "tbl_df")
27+
28+
# column names are as expected
29+
expect_equal(colnames(d), colnames(tlr_pred))
30+
31+
# calculations match those done manually
32+
manual_preds <- ifelse(d$y_pred < 1, 1, d$y_pred)
33+
manual_preds <- ifelse(manual_preds > 2, 2, manual_preds)
34+
expect_equal(manual_preds, tlr_pred$y_pred)
35+
})
36+
137
test_that("adjustment printing", {
238
expect_snapshot(tailor() %>% adjust_numeric_range())
339
expect_snapshot(tailor() %>% adjust_numeric_range(hardhat::tune()))

0 commit comments

Comments
 (0)