Add regression test: RampedHalfAndHalf initializer does not respect max_depth (#259) - #405
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.
Summary
Adds a strict-
xfailregression test documenting issue #259:RampedHalfAndHalfInitializeraccepts amax_depthargument but does not respect it.No production code is changed in this PR — the test is living evidence of the bug, and will start failing (via
xfail(strict=True)) the moment the bug is fixed, prompting removal of the marker.Root cause (for reference)
RampedHalfAndHalfInitializer.__init__storesmax_depth, butinitialize()callsrepresentation.create_genotype(random)without passing a depth-bounded decider, so the representation's default decider is used andmax_depthis silently ignored (compare withFullInitializer, which passes its own depth-boundedFullDecider). It also does not do any ramping or grow/full alternation, contrary to its docstring.How to run
Currently reports
XFAIL. To see the underlying failure, remove thexfailmarker and run again.Evidence (assertion output without the xfail marker)
The test builds a tiny recursive grammar (
Expr→Leaf|Branch(Expr, Expr)), requests a population of 20 fromRampedHalfAndHalfInitializer(max_depth=3)with a fixed seed (NativeRandomSource(5)), and asserts every individual's depth is ≤ 3:Expected: all depths ≤ 3. Actual: 5 of 20 individuals exceed the limit (depths 4, 5, 5, 6, and 9).
Checks
uv run pytest: 520 passed, 8 skipped, 1 xfailed (the new test)ruff check . --fix: all checks passedCloses nothing; references #259.