intComposition with a stars and bars implementation - #396
Open
robstoll wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new ArbExtensionPoint.intComposition(total, numberOfParts, minPart) generator based on a stars-and-bars approach, plus accompanying tests to validate generated compositions.
Changes:
- Introduce
intCompositiongenerator for producing integer compositions with a per-part minimum. - Extend
ArbNumberTestto coverintCompositionand add/expand numeric bound tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main/kotlin/com/tegonal/variist/generators/arbNumber.kt | Adds intComposition generator and validation logic. |
| src/test/kotlin/com/tegonal/variist/generators/ArbNumberTest.kt | Adds intComposition tests and additional bound tests for number arbs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+198
to
+202
| // We treat this as a stars and bars problem, so minPart can also be thought of the min. number of stars in a part | ||
| val totalMinStars = numberOfParts * minPart | ||
| require(totalMinStars <= total) { | ||
| "numberOfParts ($numberOfParts) * minPart ($minPart) must be less than or equal to total ($total)" | ||
| } |
| // including the minPart requirement. Since we moved the min stars requirement out of remainingStars, | ||
| // a bar could also be at position 0, i.e. the first part wouldn't get any remaining star. | ||
| // Due to this we introduce a virtual bar -1 at the beginning so that we can use the same formula | ||
| // also for the first part. Likewise, we add totalStarsAndBars as virtual bar at the end. Then |
Comment on lines
+199
to
+200
| @Test | ||
| fun intComposition_total8_parts4_minPart2_everyPart1() { |
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.
I confirm that I have read the Contributor Agreement v1.1, agree to be bound on them and confirm that my contribution is compliant.