Skip to content

Commit c89330f

Browse files
committed
test: achieve 100% test coverage for stochastic_simulation.R
- fixed 'RESIM (restricted)' test block to properly target the second eigen execution cycle when restricted traits are assigned - cleanly intercepted imaginary eigenvalues check on lines 732-733 - all 99 tests pass warnings reliably
1 parent c522e36 commit c89330f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

tests/testthat/test-stochastic_simulation.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,26 +720,28 @@ test_that("ESIM fires imaginary eigenvalue warning when max_imag > 1e-5 (lines 6
720720
expect_s3_class(r, "selection_simulation")
721721
})
722722

723+
# --- RESIM (restricted) imaginary eigenvalue warning: lines 732-733 -----------
723724
# --- RESIM (restricted) imaginary eigenvalue warning: lines 732-733 -----------
724725
# Same approach with restricted_traits and first RESIM call.
725726
test_that("RESIM (restricted) fires imaginary eigenvalue warning (lines 732-733)", {
726727
set.seed(5006)
727728
real_eigen <- base::eigen
728-
first_resim_call <- TRUE
729+
eigen_call_count <- 0L
729730
expect_warning(
730731
{
731732
r <- with_mocked_bindings(
732733
eigen = function(x, symmetric = FALSE, ...) {
734+
eigen_call_count <<- eigen_call_count + 1L
733735
res <- real_eigen(x, symmetric = symmetric, ...)
734-
if (first_resim_call) {
735-
first_resim_call <<- FALSE
736+
# First call is ESIM, second is restricted RESIM
737+
if (eigen_call_count == 2L) {
736738
res$values <- res$values + 1i * 0.01
737739
}
738740
res
739741
},
740742
.package = "base",
741743
simulate_selection_cycles(
742-
n_cycles = 2,
744+
n_cycles = 1,
743745
n_individuals = 50,
744746
n_loci = 10,
745747
n_traits = 2,
@@ -748,7 +750,7 @@ test_that("RESIM (restricted) fires imaginary eigenvalue warning (lines 732-733)
748750
)
749751
)
750752
},
751-
"Eigenvalues have significant imaginary parts"
753+
"RESIM \\(restricted\\).*Eigenvalues have significant imaginary parts"
752754
)
753755
expect_s3_class(r, "selection_simulation")
754756
})

0 commit comments

Comments
 (0)