Skip to content

Commit

Permalink
tests: Refactor test-ig_fet to contain random sampling in withr::with…
Browse files Browse the repository at this point in the history
…_seed()
  • Loading branch information
simpar1471 committed Feb 6, 2024
1 parent 7fa5360 commit ef3e885
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tests/testthat/test-ig_fet.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,20 @@ test_that(
for (chr_z_or_p in c("zscore", "centile")) {
xvar <- ig_fet[[acronym]][[1]][[1]]
for (seed in seq(300, 400, 30)) {
# withr::with_seed(
# seed,
# code = {
dbl_z_or_p <- rnorm(n = length(xvar))
if (chr_z_or_p == "centile") dbl_z_or_p <- pnorm(dbl_z_or_p)

fn_stem <- paste0("ig_fet_", acronym)
fn_zp2val <- get(paste0(fn_stem, "_", chr_z_or_p, "2value"))
y_gigs <- fn_zp2val(dbl_z_or_p, xvar)

fn_val2zp <- get(paste0(fn_stem, "_value2", chr_z_or_p))
gigs_z_or_p <- fn_val2zp(y_gigs, xvar)

expect_equal(gigs_z_or_p, expected = dbl_z_or_p,
tolerance = sqrt(.Machine$double.eps))
# })
dbl_z_or_p <- withr::with_seed(seed, code = {
rnorm(n = length(xvar))
})
if (chr_z_or_p == "centile") dbl_z_or_p <- pnorm(dbl_z_or_p)

fn_stem <- paste0("ig_fet_", acronym)
fn_zp2val <- get(paste0(fn_stem, "_", chr_z_or_p, "2value"))
y_gigs <- fn_zp2val(dbl_z_or_p, xvar)

fn_val2zp <- get(paste0(fn_stem, "_value2", chr_z_or_p))
gigs_z_or_p <- fn_val2zp(y_gigs, xvar)

expect_equal(gigs_z_or_p, expected = dbl_z_or_p,
tolerance = sqrt(.Machine$double.eps))
}
}
}
Expand Down

0 comments on commit ef3e885

Please sign in to comment.