test: TransTableL op-stats unit tests (#379 item 3) - #403
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit test coverage for TransTableL's op-stats counters (num_adds_, num_overwrites_, num_harvests_), instrumented in #365 but never directly tested — item 3 from #379.
Tests added (library/tests/trans_table/trans_table_l_op_stats_test.cpp):
InsertIncrementsAddsOnly — a single new entry increments adds only.
FullBlockReplacementIncrementsOverwrites — filling a block to BlocksPerEntry (125) capacity and adding one more distinct entry increments both adds and overwrites.
ResetOpStatsClearsCounters — reset_op_stats() zeroes all three counters after activity.
Implementation note: the public API has no way to fill a WinBlock to capacity, so the full-block test seeds WinBlock/WinMatch state directly via a friend class TransTableLOpStatsTest; declaration added to trans_table_l.hpp, rather than reverse-engineering add()'s internal win-rank/aggregation encoding to manufacture 125 organic collisions. Seeded entries use mask_index_ = 0 / top_set1_..4_ = 0, a combination the real encoding never produces once any suit has a nonzero win rank — so the real add() call in the test is guaranteed to take the "not found → new insert" path rather than accidentally matching a seeded entry.
Verification: compiled and ran against the real sources outside Bazel first, then confirmed each test actually catches its corresponding regression by deliberately disabling num_adds_++/num_overwrites_++ and separately reset_op_stats()'s body — each break fails exactly the test(s) it should and no others. Also compiled alongside the other three files sharing this Bazel target (trans_table_base_test.cpp, trans_table_s_test.cpp, trans_table_p_test.cpp) to rule out link-time collisions. bazelisk test //library/tests/trans_table:trans_table passes on the real toolchain.
Refs #379 (item 3 of 4 — items 1/2 covered by #397/#402; item 4, the analyse_later_board reset/report scoping question, is a separate design discussion still in progress).