tests/testthat/test-fd.R

test_that("fd() | scalar test", {
    expect_equal(fd(0), 7)
    expect_equal(fd(1), 6)
    expect_equal(fd(2), 5)
    expect_equal(fd(3), 4)
    expect_equal(fd(4), 3)
    expect_equal(fd(5), 2)
    expect_equal(fd(6), 1)
    expect_equal(fd(7), 0)
    expect_equal(fd(as.numeric(NA)), as.integer(NA))
})

test_that("fd() | vector test", {
    expect_equal(fd(c(1, 5)), c(6, 2))
    expect_equal(fd(c(4, 2)), c(3, 5))
    expect_equal(fd(c(3, NA)), c(4, NA))
})

test_that("fd() | error test", {
    # assert_numeric_(wd)
    expect_error(fd("test"), "Assertion on 'wd' failed")
    expect_error(fd(lubridate::dhours(1)), "Assertion on 'wd' failed")
    expect_error(fd(lubridate::minutes(1)), "Assertion on 'wd' failed")

    # checkmate::assert_integerish(wd, lower = 0, upper = 7)
    expect_error(fd(1.5), "Assertion on 'wd' failed")
    expect_error(fd(10), "Assertion on 'wd' failed")
    expect_error(fd(-1), "Assertion on 'wd' failed")
    expect_error(fd(c(1, 10)), "Assertion on 'wd' failed")
})

Try the mctq package in your browser

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

mctq documentation built on March 7, 2023, 8:22 p.m.