Skip to content

Commit

Permalink
refactor test using new TaskSurv function
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Aug 16, 2024
1 parent ac2a761 commit 3ff4218
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/testthat/test_partition.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
test_that("partition w/ stratification works", {
task = tsk("rats")
sets = partition(task)
with_seed(42, {
task = tsk("rats")
part = partition(task, ratio = 0.8)

ratio = function(status) {
tab = table(status)
unname(tab[1L] / tab[2L])
}
ratio = function(status) {
tab = table(status)
unname(tab[1L] / tab[2L])
}

all = ratio(task$status())
train = ratio(task$status(sets$train))
test = ratio(task$status(sets$test))
all = task$cens_prop()
train = task$cens_prop(rows = part$train)
test = task$cens_prop(rows = part$test)

expect_numeric(all, lower = 6, upper = 6.2)
expect_numeric(train, lower = 6, upper = 6.2)
expect_numeric(test, lower = 6, upper = 6.2)
expect_equal(all, train, tolerance = 0.01)
expect_equal(all, test, tolerance = 0.01)
})
})

0 comments on commit 3ff4218

Please sign in to comment.