tests/testthat/test-randrows.R

# Create a sample data frame for testing
sample_data <- data.frame(
  ID = 1:10,
  Name = c("Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Hannah", "Ivy", "Jack")
)

# Test case 1: Custom number of rows (e.g., 3)
test_that("Custom number of rows (e.g., 3)", {
  result <- randrows(sample_data, n = 3)
  expect_true(nrow(result) == 3)
})

# Test case 2: Ensure n is not bigger than the actual number of rows
test_that("Ensure n is not bigger than the actual number of rows", {
  expect_error(randrows(sample_data, n = 11))
})

Try the esmtools package in your browser

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

esmtools documentation built on May 29, 2024, 6:45 a.m.