Skip to content

Commit

Permalink
many skips
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Oct 16, 2024
1 parent f401411 commit cf115f6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test-cal-apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ test_that("Logistic apply works - data.frame", {
})

test_that("Logistic apply works - tune_results", {
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_logistic <- cal_estimate_logistic(tct, smooth = FALSE)
tap_logistic <- cal_apply(tct, tl_logistic)
Expand All @@ -27,6 +29,8 @@ test_that("Logistic spline apply works", {
})

test_that("Logistic spline apply works - tune_results", {
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_gam <- cal_estimate_logistic(tct)
tap_gam <- cal_apply(tct, tl_gam)
Expand Down Expand Up @@ -90,6 +94,8 @@ test_that("Isotonic apply works - data.frame", {
})

test_that("Isotonic apply works - tune_results", {
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_isotonic <- cal_estimate_isotonic(tct)
tap_isotonic <- cal_apply(tct, tl_isotonic)
Expand All @@ -107,6 +113,8 @@ test_that("Isotonic Bootstrapped apply works - data.frame", {
})

test_that("Isotonic Bootstrapped apply works - tune_results", {
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_boot <- cal_estimate_isotonic_boot(tct)
tap_boot <- cal_apply(tct, tl_boot)
Expand All @@ -119,6 +127,7 @@ test_that("Isotonic Bootstrapped apply works - tune_results", {
# ------------------------------------------------------------------------------

test_that("Beta apply works - data.frame", {
skip_if_not_installed("betacal")
sl_beta <- cal_estimate_beta(segment_logistic, Class)
ap_beta <- cal_apply(segment_logistic, sl_beta)

Expand All @@ -128,6 +137,9 @@ test_that("Beta apply works - data.frame", {
})

test_that("Beta apply works - tune_results", {
skip_if_not_installed("betacal")
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_beta <- cal_estimate_beta(tct)
tap_beta <- cal_apply(tct, tl_beta)
Expand All @@ -148,12 +160,16 @@ test_that("Passing the data frame first returns expected abort message", {
})

test_that("Passing a tune_results without saved predictions causes error", {
skip_if_not_installed("betacal")
skip_if_not_installed("modeldata")

tct <- testthat_cal_binary()
tl_beta <- cal_estimate_beta(tct)
expect_error(cal_apply(tune::ames_grid_search, tl_beta))
})

test_that("Passing a calibration object as the first arg fails", {
skip_if_not_installed("betacal")
sl_beta <- cal_estimate_beta(segment_logistic, Class)
expect_error(cal_apply(sl_beta, segment_logistic))
})
34 changes: 28 additions & 6 deletions tests/testthat/test-cal-estimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ test_that("Logistic estimates work - data.frame", {
})

test_that("Logistic estimates work - tune_results", {
skip_if_not_installed("modeldata")

tl_logistic <- cal_estimate_logistic(testthat_cal_binary(), smooth = FALSE)
expect_cal_type(tl_logistic, "binary")
expect_cal_method(tl_logistic, "Logistic regression")
Expand Down Expand Up @@ -101,6 +103,8 @@ test_that("Logistic spline estimates work - data.frame", {
})

test_that("Logistic spline estimates work - tune_results", {
skip_if_not_installed("modeldata")

tl_gam <- cal_estimate_logistic(testthat_cal_binary())
expect_cal_type(tl_gam, "binary")
expect_cal_method(tl_gam, "Generalized additive model")
Expand Down Expand Up @@ -154,6 +158,8 @@ test_that("Isotonic estimates work - data.frame", {
})

test_that("Isotonic estimates work - tune_results", {
skip_if_not_installed("modeldata")

set.seed(100)
tl_isotonic <- cal_estimate_isotonic(testthat_cal_binary())
expect_cal_type(tl_isotonic, "binary")
Expand Down Expand Up @@ -250,6 +256,8 @@ test_that("Isotonic Bootstrapped estimates work - data.frame", {
})

test_that("Isotonic Bootstrapped estimates work - tune_results", {
skip_if_not_installed("modeldata")

set.seed(100)
tl_isotonic <- cal_estimate_isotonic_boot(testthat_cal_binary())
expect_cal_type(tl_isotonic, "binary")
Expand Down Expand Up @@ -286,6 +294,7 @@ test_that("Isotonic Bootstrapped estimates errors - grouped_df", {

# ----------------------------------- Beta -------------------------------------
test_that("Beta estimates work - data.frame", {
skip_if_not_installed("betacal")
sl_beta <- cal_estimate_beta(segment_logistic, Class, smooth = FALSE)
expect_cal_type(sl_beta, "binary")
expect_cal_method(sl_beta, "Beta calibration")
Expand Down Expand Up @@ -319,6 +328,9 @@ test_that("Beta estimates work - data.frame", {
})

test_that("Beta estimates work - tune_results", {
skip_if_not_installed("betacal")
skip_if_not_installed("modeldata")

tl_beta <- cal_estimate_beta(testthat_cal_binary())
expect_cal_type(tl_beta, "binary")
expect_cal_method(tl_beta, "Beta calibration")
Expand All @@ -335,27 +347,31 @@ test_that("Beta estimates work - tune_results", {

set.seed(100)
suppressWarnings(
mtnl_isotonic <- cal_estimate_beta(testthat_cal_multiclass())
mtnl_beta <- cal_estimate_beta(testthat_cal_multiclass())
)
expect_cal_type(mtnl_isotonic, "one_vs_all")
expect_cal_method(mtnl_isotonic, "Beta calibration")
expect_snapshot(print(mtnl_isotonic))
expect_true(are_groups_configs(mtnl_isotonic))
expect_cal_type(mtnl_beta, "one_vs_all")
expect_cal_method(mtnl_beta, "Beta calibration")
expect_snapshot(print(mtnl_beta))
expect_true(are_groups_configs(mtnl_beta))

expect_equal(
testthat_cal_multiclass_count(),
nrow(cal_apply(testthat_cal_multiclass(), mtnl_isotonic))
nrow(cal_apply(testthat_cal_multiclass(), mtnl_beta))
)
})

test_that("Beta estimates errors - grouped_df", {
skip_if_not_installed("betacal")
expect_snapshot_error(
cal_estimate_beta(dplyr::group_by(mtcars, vs))
)
})

# ------------------------------ Multinomial -----------------------------------
test_that("Multinomial estimates work - data.frame", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")

sp_multi <- cal_estimate_multinomial(species_probs, Species, smooth = FALSE)
expect_cal_type(sp_multi, "multiclass")
expect_cal_method(sp_multi, "Multinomial regression")
Expand Down Expand Up @@ -390,6 +406,9 @@ test_that("Multinomial estimates work - data.frame", {
})

test_that("Multinomial estimates work - tune_results", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")

tl_multi <- cal_estimate_multinomial(testthat_cal_multiclass(), smooth = FALSE)
expect_cal_type(tl_multi, "multiclass")
expect_cal_method(tl_multi, "Multinomial regression")
Expand Down Expand Up @@ -421,6 +440,9 @@ test_that("Multinomial estimates work - tune_results", {
})

test_that("Multinomial estimates errors - grouped_df", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")

expect_snapshot_error(
cal_estimate_multinomial(dplyr::group_by(mtcars, vs))
)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-cal-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ test_that("Binary breaks functions work with group argument", {
})

test_that("Multi-class breaks functions work", {
skip_if_not_installed("modeldata")

x10 <- .cal_table_breaks(species_probs, Species, dplyr::starts_with(".pred"))

expect_equal(
Expand Down Expand Up @@ -123,6 +125,8 @@ test_that("breaks plot function errors - grouped_df", {
})

test_that("Binary logistic functions work", {
skip_if_not_installed("modeldata")

x20 <- .cal_table_logistic(segment_logistic, Class, .pred_good)

model20 <- mgcv::gam(Class ~ s(.pred_good, k = 10),
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-cal-validate.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("Logistic validation with data frame input", {
skip_if_not_installed("rsample")

df <- testthat_cal_sampled()
val_obj <- cal_validate_logistic(df, Class)
val_with_pred <- cal_validate_logistic(df, Class, save_pred = TRUE, smooth = TRUE)
Expand Down Expand Up @@ -59,6 +61,9 @@ test_that("Logistic validation with data frame input", {


test_that("Beta validation with data frame input", {
skip_if_not_installed("betacal")
skip_if_not_installed("rsample")

df <- testthat_cal_sampled()
val_obj <- cal_validate_beta(df, Class)
val_with_pred <- cal_validate_beta(df, Class, save_pred = TRUE)
Expand Down Expand Up @@ -87,6 +92,8 @@ test_that("Beta validation with data frame input", {


test_that("Isotonic validation classification with data frame input", {
skip_if_not_installed("rsample")

df <- testthat_cal_sampled()
val_obj <- cal_validate_isotonic(df, Class)
val_with_pred <- cal_validate_isotonic(df, Class, save_pred = TRUE)
Expand Down Expand Up @@ -114,6 +121,8 @@ test_that("Isotonic validation classification with data frame input", {
})

test_that("Bootstrapped Isotonic classification validation with data frame input", {
skip_if_not_installed("rsample")

df <- testthat_cal_sampled()
val_obj <- cal_validate_isotonic_boot(df, Class)
val_with_pred <- cal_validate_isotonic_boot(df, Class, save_pred = TRUE)
Expand Down Expand Up @@ -141,6 +150,9 @@ test_that("Bootstrapped Isotonic classification validation with data frame input
})

test_that("Multinomial classification validation with data frame input", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")

df <- rsample::vfold_cv(testthat_cal_sim_multi())
val_obj <- cal_validate_multinomial(df, class)
val_with_pred <- cal_validate_multinomial(df, class, save_pred = TRUE, smooth = TRUE)
Expand Down Expand Up @@ -350,6 +362,7 @@ test_that("Bootstrapped isotonic classification validation with `fit_resamples`"
})

test_that("Beta calibration validation with `fit_resamples`", {
skip_if_not_installed("betacal")
res <- testthat_cal_fit_rs()
val_obj <- cal_validate_beta(res$binary)
val_with_pred <- cal_validate_beta(res$binary, save_pred = TRUE)
Expand Down Expand Up @@ -382,6 +395,9 @@ test_that("Beta calibration validation with `fit_resamples`", {
})

test_that("Multinomial calibration validation with `fit_resamples`", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")

res <- testthat_cal_fit_rs()
val_obj <- cal_validate_multinomial(res$multin)
val_with_pred <- cal_validate_multinomial(res$multin, save_pred = TRUE, smooth = TRUE)
Expand Down Expand Up @@ -564,6 +580,10 @@ test_that("Isotonic bootstrapped regression validation with `fit_resamples`", {


test_that("validation functions error with tune_results input", {
skip_if_not_installed("modeldata")
skip_if_not_installed("nnet")
skip_if_not_installed("beta")

expect_snapshot_error(
cal_validate_beta(testthat_cal_binary())
)
Expand Down

0 comments on commit cf115f6

Please sign in to comment.