1.2 KiB
1.2 KiB
Plan: Fix DiceRoll Success Counting Bug (Issue #16)
Summary
The DiceRoll.roll() method computes numberOfSuccesses from the stale this.result list instead of the freshly rolled values. The fix is to capture the new roll in a local variable before passing it to copy(), so both result and numberOfSuccesses reference the same fresh data.
Steps
Step 1: Fix Dice.kt
File: sharedUI/src/commonMain/kotlin/org/shahondin1624/lib/functions/Dice.kt
Change the roll() method to:
- Roll dice into a local
val newResult - Count successes from
newResult - Pass both to
copy()
Step 2: Write unit test
File: sharedUI/src/commonTest/kotlin/org/shahondin1624/DiceTest.kt
Create a new test file with:
- Test that after
roll(),numberOfSuccessesequals the count of values >= threshold inresult - Test with default threshold (5) and custom threshold
- Test that
resultlist has correct size (matchesnumberOfDice) - Test the
countSuccessesextension function directly
AC Verification Checklist
numberOfSuccessesis computed from newly rolled values (not stale result list)- Unit test verifying correct success count after
.roll()