Skip to content

Commit

Permalink
metric test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Dec 5, 2023
1 parent a340985 commit 620d048
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
10 changes: 0 additions & 10 deletions tests/testthat/test-eval-time-single-selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,3 @@ test_that("selecting single eval time - mixed metric sets - integrated first", {
expect_null(int_multi)
})


test_that("selecting the first metric", {
met_1 <- metric_set(rmse)
tbl_1 <- tibble::as_tibble(met_1)[1,]
met_2 <- metric_set(rmse, ccc)
tbl_2 <- tibble::as_tibble(met_2)[1,]

expect_equal(first_metric(met_1), tbl_1)
expect_equal(first_metric(met_2), tbl_2)
})
54 changes: 54 additions & 0 deletions tests/testthat/test-metric-single-selection.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

test_that("selecting the first metric", {
met_1 <- metric_set(rmse)
tbl_1 <- tibble::as_tibble(met_1)[1,]
met_2 <- metric_set(rmse, ccc)
tbl_2 <- tibble::as_tibble(met_2)[1,]

expect_equal(first_metric(met_1), tbl_1)
expect_equal(first_metric(met_2), tbl_2)
})

test_that("selecting a metric", {
# much of this is indirectly tested in show/select best

data("example_ames_knn")
expect_snapshot(
choose_metric(ames_grid_search, "rmse")
)
expect_snapshot(
choose_metric(ames_grid_search, NULL)
)
expect_snapshot(
choose_metric(ames_grid_search, "potato"),
error = TRUE
)
expect_snapshot(
choose_metric(ames_grid_search, c("rmse", "ccc"))
)
})

test_that("identify survival metrics", {

expect_false(
metric_set(rmse) %>%
as_tibble() %>%
tune:::is_survival_metric()
)

expect_true(
metric_set(brier_survival_integrated) %>%
as_tibble() %>%
tune:::is_survival_metric()
)

expect_true(
metric_set(brier_survival, concordance_survival) %>%
as_tibble() %>%
tune:::is_survival_metric()
)

})



0 comments on commit 620d048

Please sign in to comment.