Skip to content

Commit 0eae303

Browse files
committed
test basic adjust_equivocal_zone() usage
1 parent 05c00b6 commit 0eae303

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/testthat/test-adjust-equivocal-zone.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
test_that("basic adjust_equivocal_zone() usage works", {
2+
skip_if_not_installed("modeldata")
3+
library(dplyr)
4+
library(modeldata)
5+
6+
# fitting and predicting happens without raising conditions
7+
expect_no_condition(
8+
tlr <-
9+
tailor() %>%
10+
adjust_equivocal_zone(value = 1 / 4)
11+
)
12+
13+
expect_no_condition(
14+
tlr_fit <- fit(
15+
tlr,
16+
two_class_example,
17+
outcome = c(truth),
18+
estimate = c(predicted),
19+
probabilities = c(Class1, Class2)
20+
)
21+
)
22+
23+
expect_no_condition(
24+
tlr_pred <- predict(tlr_fit, two_class_example)
25+
)
26+
27+
# classes are as expected
28+
expect_s3_class(tlr, "tailor")
29+
expect_s3_class(tlr_fit, "tailor")
30+
expect_s3_class(tlr_pred, "tbl_df")
31+
expect_s3_class(tlr_pred$predicted, "class_pred")
32+
33+
# column names are as expected
34+
expect_equal(colnames(two_class_example), colnames(tlr_pred))
35+
36+
# prediction classes are as expected
37+
expect_equal(levels(tlr_pred$predicted), levels(two_class_example$predicted))
38+
expect_equal(attr(tlr_pred$predicted, "equivocal"), "[EQ]")
39+
40+
# calculations match those done manually
41+
tlr_pred_col <- as.character(tlr_pred$predicted)
42+
manual_pred_col <- ifelse(two_class_example$Class1 > .5, "Class1", "Class2")
43+
manual_pred_col <-
44+
ifelse(
45+
two_class_example$Class1 > .25 & two_class_example$Class1 < .75,
46+
NA_character_,
47+
manual_pred_col
48+
)
49+
expect_equal(tlr_pred_col, manual_pred_col)
50+
})
51+
52+
# TODO: test sensitivity to function arguments
53+
154
test_that("adjustment printing", {
255
expect_snapshot(tailor() %>% adjust_equivocal_zone())
356
expect_snapshot(tailor() %>% adjust_equivocal_zone(hardhat::tune()))

0 commit comments

Comments
 (0)