tests/testthat/test-check_sort_by.R

testthat::test_that("check_sort_by tests", {
  # Test 1: Valid single set option
  sort_by_test_1 <- ".upper"
  testthat::expect_no_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_1))

  # Test 2: Valid all categories in the data frame
  sort_by_test_2 <- c("Not at all", "A bit", "A lot")
  testthat::expect_no_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_2))

  # Test 2: Valid all categories in the data frame
  sort_by_test_2 <- c("Not at all", "A bit")
  testthat::expect_no_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_2))

  # Test 2: Error on not all categories in the data frame
  sort_by_test_2 <- c("Not at all", "A bit", "A lot")
  testthat::expect_error(
    saros:::check_sort_by(x = c("Not at all", "A bit"),
                               sort_by = sort_by_test_2))


  # Test 3: Invalid single set option
  sort_by_test_3 <- ".invalid_option"
  testthat::expect_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_3))

  # Test 4: Invalid character vector with mixed valid and invalid categories
  sort_by_test_4 <- c("Not at all", "A bit", "Invalid")
  testthat::expect_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_4))

  # Test 5: NULL sort_by (default)
  sort_by_test_5 <- NULL
  testthat::expect_no_error(
    saros:::check_sort_by(x = c("Not at all", "A bit", "A lot"),
                               sort_by = sort_by_test_5))
})

Try the saros package in your browser

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

saros documentation built on June 8, 2025, 10:43 a.m.