[Analytics] Return zero instead of NaN for impossible draw probabilities

The draw-probability widget computes a hypergeometric probability as a sum of
qLn terms. Two argument combinations reach a non-positive term and return NaN,
which the results table prints as "nan":

- k > K, asking for more copies than the deck holds. A deck with one Forest,
  draw 7, "exactly 3" gives K=1, k=3.
- n - k > N - K, where drawing k targets would need more non-target cards than
  exist. An 8-card deck with 6 targets, draw 5, "exactly 0" gives N-K=2, n-k=5.

Both are reachable: the quantity and drawn spinboxes allow 1-60, and the
"at least" branch caps k at copies while the "exactly" branch passes the spinbox
value straight through.

Extract the function so it can be tested on its own, and guard both cases.
Restoring the old guard fails 3 of the 7 new tests.
This commit is contained in:
Lukas Brübach 2026-10-05 12:01:50 +02:00
parent 90bb3b8807
commit a438be8bda
7 changed files with 134 additions and 21 deletions

View file

@ -274,6 +274,15 @@ cockatrice_add_test(
INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/cockatrice/src
)
cockatrice_add_test(
NAME
hypergeometric_probability_test
SOURCES
${CMAKE_SOURCE_DIR}/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability/hypergeometric_probability.cpp
hypergeometric_probability_test.cpp
INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability
)
cockatrice_add_test(
NAME
lag_monitor_test