|
| 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 | + |
1 | 37 | test_that("adjustment printing", {
|
2 | 38 | expect_snapshot(tailor() %>% adjust_numeric_range())
|
3 | 39 | expect_snapshot(tailor() %>% adjust_numeric_range(hardhat::tune()))
|
|
0 commit comments