Type: | Package |
Title: | Testing for R Packages with Multiple Attempts for Noisy Tests |
Version: | 0.1.0 |
Author: | Collin Erickson |
Maintainer: | Collin Erickson <collinberickson@gmail.com> |
Description: | Runs tests using the 'testthat' package but allows for multiple attempts for a single test. This is useful for noisy or flaky tests that generally pass but can fail due to occasional random errors, such as numeric instability or using random data. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
Suggests: | testthat (≥ 3.0.0), rlang |
Config/testthat/edition: | 3 |
Language: | en-US |
NeedsCompilation: | no |
Packaged: | 2024-02-03 23:13:41 UTC; colli |
Repository: | CRAN |
Date/Publication: | 2024-02-05 20:20:02 UTC |
Test that with multiple attempts
Description
Test that with multiple attempts
Usage
ttm(n, expr, verbose = 0)
Arguments
n |
Maximum number of attempts |
expr |
Expression to evaluate |
verbose |
Amount that should be printed |
Value
Nothing
Examples
set.seed(0)
# 1 attempt, all pass
ttm(1, {
ttm_expect_true(TRUE)
ttm_expect_true(1 == 1)
ttm_expect_true(all(1:5 == 1:5))
})
# Fails first 10 times, then passes
ttm(100, {
x <- runif(1)
print(x)
ttm_expect_true(x < 0.1)
})
# Will always fail regardless of number of attempts
try({
ttm(3, {
ttm_expect_true(1 == 2)
})
})
Test that multi: expect equal
Description
Test that multi: expect equal
Usage
ttm_expect_equal(
object,
expected,
...,
tolerance = if (testthat::edition_get() >= 3) testthat::testthat_tolerance(),
info = NULL,
label = NULL,
expected.label = NULL,
verbose = 0
)
Arguments
object |
Object to check if equal to expected |
expected |
Expected value |
... |
Args passed to testthat::expect_equal() |
tolerance |
Passed to 'testthat::expect_true()'. |
info |
Passed to 'testthat::expect_true()'. |
label |
Passed to 'testthat::expect_true()'. |
expected.label |
Passed to 'testthat::expect_true()'. |
verbose |
Amount of info that should be printed. |
Value
Test result
Examples
set.seed(0)
# 1 attempt, all pass
ttm(1, {
ttm_expect_equal(TRUE, TRUE)
ttm_expect_equal(1, 1)
ttm_expect_equal(1:5, 1:5)
})
# Fails first 6 times, then passes
ttm(100, {
x <- sample(1:6, 1)
print(x)
ttm_expect_equal(x, 3)
})
# Will always fail regardless of number of attempts
try({
ttm(3, {
ttm_expect_equal(1, 2)
})
})
Test that multi: expect true
Description
See 'testthat::expect_true' for details.
Usage
ttm_expect_true(object, info = NULL, label = NULL, verbose = 0)
Arguments
object |
Object to test. |
info |
Passed to 'testthat::expect_true()'. |
label |
Passed to 'testthat::expect_true()'. |
verbose |
Amount of info that should be printed. |
Value
Test result
Examples
set.seed(0)
# 1 attempt, all pass
ttm(1, {
ttm_expect_true(TRUE)
ttm_expect_true(1 == 1)
ttm_expect_true(all(1:5 == 1:5))
})
# Fails first 10 times, then passes
ttm(100, {
x <- runif(1)
print(x)
ttm_expect_true(x < 0.1)
})
# Will always fail regardless of number of attempts
try({
ttm(3, {
ttm_expect_true(1 == 2)
})
})