tests/testthat/test_add_lagging_point_zero.R

test_that("add_lagging_point_zero() returns objects of the correct class.", {
  expect_type(add_lagging_point_zero(c(0.01, 0.002)), "character")
  expect_type(add_lagging_point_zero(c(0.01, 0.02)), "character")
  expect_type(add_lagging_point_zero(c(1, 2, 3), ignore = TRUE), "double")
})

test_that("add_lagging_point_zero() returns numbers to the same precision.", {
  expect_true(all(nchar(add_lagging_point_zero(c(0.01, 0.002), 10)) == 12))
})

test_that("add_lagging_point_zero() returns the correct number of decimal places.", {
  ndp <- function(x) nchar(stringr::str_split_fixed(x, "[.]", 2)[, 2])
  expect_equal(ndp(add_lagging_point_zero(c(0.01, 0.002), 10)), c(10, 10))
})
edwardlavender/prettyGraphics documentation built on Jan. 19, 2025, 2:47 p.m.