tests/testthat/test-fmt_int.R

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for atomic integer", {
  expect_equal(fmt_int(6), "6")
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for atomic integerish", {
  expect_equal(fmt_int(5.0), "5")
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for atomic integerish within tol", {
  expect_equal(fmt_int(5.0001, tol = 1.0e-4), "5")
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for integer vector", {
  expect_equal(fmt_int(c(1, 467, 25)), c("  1", "467", " 25"))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for padding char of '0'", {
  expect_equal(fmt_int(c(1, 467, 25), pad_char = "0"), c("001", "467", "025"))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for padding char of '.'", {
  expect_equal(fmt_int(c(1, 467, 25), pad_char = "."), c("..1", "467", ".25"))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int works for padding char of '--'", {
  expect_equal(fmt_int(c(25, 3, 482), pad_char = "--"),
               c("--25", "----3", "482"))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int preserves names if requested", {
  expect_equal(fmt_int(c(a = 1, b = 20), preserve_names = TRUE),
               c(a = " 1", b = "20"))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails for atomic double value", {
  expect_jute_error(fmt_int(4.3))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails with message for atomic double value", {
  expect_snapshot(fmt_int(4.3), error = TRUE)
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails for atomic non-integerish value", {
  expect_jute_error(fmt_int(5.0002, tol = 1.0e-4))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails with message for atomic non-integerish value", {
  expect_snapshot(fmt_int(5.0002, tol = 1.0e-4), error = TRUE)
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails for double vector", {
  expect_jute_error(fmt_int(c(1, 4.3, 5)))
})

# ---------------------------------------------------------------------------- #
test_that("fmt_int fails with message for double vector", {
  expect_snapshot(fmt_int(c(1, 4.3, 5)), error = TRUE)
})

# ---------------------------------------------------------------------------- #
toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.