tests/testthat/test-random-resample.R

context("random resampling")
count_1 <- sum(wine$type == 1)
for (try in 1:10) {
  test_that("Random undersampling should not have duplicate rows", {
    rand_resamp <- resample_random(wine, 1, "type", count_1 - 1)
    expect_true(no_dupe_rows(rand_resamp))
  })
}

for (try in 1:10) {
  test_that("Random oversampling should include all of the original data", {
    rand_resamp <- resample_random(wine, 1, "type", round(count_1 * 1.2))
    merged <- merge(rand_resamp, wine)
    nrow_merge <- nrow(merged[!duplicated(merged), ])
    expect_true(nrow_merge == count_1)
  })
}

Try the scutr package in your browser

Any scripts or data that you put into this service are public.

scutr documentation built on Nov. 18, 2023, 1:08 a.m.