test(nni): pin IW score returned by nni_search to independent recompute#245
Merged
Conversation
Closes the coverage gap that let the IW NNI rescore bug (3df9088) ship. The existing IW NNI test (test-ts-spr-nni-opt.R) only asserted result$score >= 0 and topology shape — it never cross-checked that the returned score matched the IW score of the returned topology. Pre-fix, nni_search did new_score = best_score + integer_delta unconditionally, so under IW the returned score was the accumulated wrong float and the existing assertions still passed. New file mirrors the EW pattern from "NNI: 15-tip random dataset" (result$score == ts_score(rt, ds)) but under concavity=10, sweeps a few concavities, and exercises multistate + NA cases. Profile parsimony isn't reached because ts_nni_search's Rcpp bridge doesn't forward infoAmounts; the IW path through compute_weighted_score is the same codepath the fix unified, so this catches both modes at the C++ level. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Closes the test coverage gap that allowed the IW NNI rescore bug (3df9088) to be committed without detection. The existing IW NNI test only asserted
result$score >= 0and topology shape — it never cross-checked that the returned score matched the IW score of the returned topology.Pre-fix,
nni_searchdidnew_score = best_score + integer_deltaunconditionally, mixing a float IW score with an integer EW step count. The returnedresult$scorewas the accumulated garbage value. The existing test would still pass because the assertions were weak.Changes
tests/testthat/test-ts-nni-iw-rescore.Rwith 4 test cases and 20 assertions:ts_fitch_scoreandTreeLengthAll tests pass with the fix in place; the pattern (assert
result$score == ts_score(rt, ds, concavity=10)) would have caught the pre-fix bug because integer EW deltas don't translate to IW score changes.Notes
Profile parsimony isn't directly testable here because
ts_nni_search's Rcpp bridge doesn't forwardinfoAmounts. However, the IW path exercises the samecompute_weighted_scoredispatch that the fix unified for both modes, so this closes the C++ entry-point gap.