Fix Dice.roll() ValueError for sides=0, matching ROM's dice() - #14
Merged
Conversation
randrange(1, 1) is an empty range, so any Dice with sides == 0 -- including a default-constructed Dice() -- raised ValueError. ROM's dice() (src/db.c) defines size 0 as rolling 0, so a 0-sided roll now returns just the bonus. Negative sides follow ROM's number_range(), which clamps a degenerate range to its low bound (1 per die). Fixes #8 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HfQ678eD83tiAALqNkct1U
ctoth
force-pushed
the
fix/dice-roll-zero-sides
branch
from
July 27, 2026 00:45
a54c799 to
3be59a1
Compare
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.
Fixes #8.
Dice.roll()raisedValueError: empty range in randrange(1, 1)for any dice withsides == 0, including a default-constructedDice(). ROM'sdice()(src/db.c) defines size 0 as rolling 0, so a 0-sided roll now returns just the bonus.Negative sides (which also crashed) follow ROM's
number_range(), which clamps a degenerate range to its low bound — 1 per die.Verification
test_dice_roll_zero_sides_contributes_zeroandtest_dice_roll_negative_sides_rolls_one_per_diefailed with the issue's exactValueErrorbefore the fix, pass after.Dice(number=2, sides=0, bonus=0).roll()→0;Dice().roll()→0;Dice(number=5, sides=0, bonus=7).roll()→7.🤖 Generated with Claude Code
https://claude.ai/code/session_01HfQ678eD83tiAALqNkct1U