tests/testthat/test-sample_frac.r

context("test-sampe_frac")

setup({
  a = data.frame(a = 1:100, b = 1:100)
  
  as.disk.frame(a, file.path(tempdir(), "tmp_sample_frac.df"), nchunks = 5, overwrite = T)
})

test_that("testing sample_frac", {
  a = disk.frame(file.path(tempdir(), "tmp_sample_frac.df"))
  a40 <- sample_frac(a, 0.4) %>% collect
  
  expect_equal(nrow(a40), 40)
  
  expect_error(a40 <- sample_frac(a, 0.4, weight = 1) %>% collect)
})

teardown({
  fs::dir_delete(file.path(tempdir(), "tmp_sample_frac.df"))
})
xiaodaigh/disk.frame documentation built on Feb. 3, 2023, 10:04 p.m.