Skip to content

Tests for get_allele_freqs, compute_reference_prop and cpt_population - #39

Merged
MarsicoFL merged 1 commit into
MarsicoFL:mainfrom
ibrhmyi:tests-uncovered-exports
Nov 28, 2026
Merged

MarsicoFL merged 1 commit into
MarsicoFL:mainfrom
ibrhmyi:tests-uncovered-exports

Conversation

@ibrhmyi

@ibrhmyi ibrhmyi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

First part of the uncovered exports task, the three you suggested starting with.

I ran covr::package_coverage(type = "tests") on main first to confirm the grep. 12 of the 13 are at 0%. get_allele_freqs is the exception: it's at 100% because other tests reach it, so it was covered indirectly like you thought. I still added a test for it since nothing checked its output.

Each file has a case worked out by hand:

  • get_allele_freqs: a 4-allele table typed in, plus a check that every bundled database keeps all its markers and allele names
  • compute_reference_prop: 5 people with known combinations (2/5, 1/5, ...), plus a direct count against sim_reference_pop()
  • cpt_population: the full 4 x 5 table written as the product of marginals, plus margins and the normalising warnings

To make sure the tests can actually fail I broke each function on purpose and reran:

alleles names reversed       -> failed expectations: 290
off-by-one denominator       -> failed expectations: 7
inclusive age count in T1p   -> failed expectations: 4
devtools::test()
[ FAIL 0 | WARN 6 | SKIP 3 | PASS 2934 ]

Something that looks wrong, R/cpt_population.R:109 and 128-133. When the age range goes past [1, 80] it warns "clamping to valid range", but it never clamps:

cpt_population(MPa = 40, MPr = 50)
#           1      2        3        4       5
# F-T1  0.1875  0.125  0.15625  0.09375  0.0625
# F-T0 -0.0375 -0.025 -0.03125 -0.01875 -0.0125

So you get negative probabilities. With MPa = 78, MPr = 6 it uses P(T1) = 12/80 even though only ages 72..80 exist. The app's build_cpt_pop() does clamp (max(1, MPa - MPr)), so the two disagree. I didn't add a test for this because I'm not sure which fix you want (clamp like the app, or error), and the function is soft-deprecated anyway.

The other 10 functions come in later PRs.

…tion

Each file has at least one case worked out by hand (a small table for
get_allele_freqs and compute_reference_prop, the product of marginals
for cpt_population), so a wrong result fails instead of being compared
with itself.
@MarsicoFL
MarsicoFL merged commit 70c189d into MarsicoFL:main Nov 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants