test: analyse_later_board TT counter reset/report (#379 item 4) - #407
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Address the requested helper reuse, complete counter assertions, and naming consistency.
Review effort: Lite
Findings: 3
Open (3)
What changed in this PR
Adds TT counter reset/reporting to analyse_later_board() with coverage for normal and last-trick exits.
Changes:
- Adds TT statistics reporting and counter resets.
- Adds deterministic lifecycle tests.
- Registers the new Bazel test target.
| File | Summary |
|---|---|
library/src/solver_if.cpp |
Implements TT counter lifecycle and reporting. |
library/tests/solve_board/analyse_later_board_tt_stats_test.cpp |
Adds reset and reporting integration tests. |
library/tests/solve_board/BUILD.bazel |
Registers the test target. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ions, snake_case helpers
|
Addressed in 9ae71e9 and f1eff63. Hits are covered by the sentinel check, and op-stats are covered by comparing two runs that differ only in a manual reset_op_stats(), so it doesn't depend on how much work the later search does. |

Adds the reset/report lifecycle for analyse_later_board(), item 4 of #379 and the last remaining item.
Change (library/src/solver_if.cpp)
analyse_later_board() reuses the caller's warm SolverContext/TT across a whole AnalysePlayBin call. It previously had no counter reset and no DDS_PRINT_TT_STATS report at all.
It now resets tt_lookup_count, tt_hit_count and the TT op-stats at entry. Only the counters are reset. The warm TT is deliberately left untouched, per the #157 warm-context contract.
It reports on both the normal exit and the cardCount<=4 last-trick early return, which previously reported nothing.
The reporting now lives in one shared print_tt_stats() helper, including the n/a TransTableS case from #393. solve_board_internal, solve_same_board and analyse_later_board all call it, replacing the two duplicated inline blocks.
Tests (library/tests/solve_board/analyse_later_board_tt_stats_test.cpp)
ResetsLookupAndHitCountersIndependentlyOfPriorSolve seeds tt_lookup_count and tt_hit_count with a large sentinel just before a direct analyse_later_board call. It confirms the printed counts can't include the sentinel.
ResetsTtOpStatsIndependentlyOfPriorSolve covers op-stats, which have no public setter to poison. It compares two identical runs, one with an extra manual reset_op_stats() before the call. If analyse_later_board really resets, both print identical adds, overwrites and harvests. This doesn't depend on how much work the later search does. It forces DDS_TT_KIND=large so the counts are real numbers, not n/a.
ReportsOnBothNormalAndLastTrickEarlyReturnExits drives a full play through the real AnalysePlayPBN on a forced one-suit-per-hand deal. It confirms every card, including the last-trick early return, gets its own report.
Verification
Each of the three resets (lookups, hits, op-stats) was disabled individually. Each break is caught only by the test meant to catch it.
The tests also fail against the pre-fix code.
#402's tt_print_stats_test still passes against the refactored solve_board_internal and solve_same_board.
Both test targets pass under bazelisk.
Closes #379.