fix: compute DiceRoll success count from fresh roll, not stale result (Closes #16)

The DiceRoll.roll() method was counting successes from `this.result`
(the stale/empty list from before rolling) instead of the newly rolled
values. Fixed by capturing the new roll in a local variable before
passing it to copy(). Added 6 unit tests covering the fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shahondin1624
2026-03-13 12:22:30 +01:00
parent 3834c4fc8e
commit 1b75bc0b69
3 changed files with 123 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
# 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:
1. Roll dice into a local `val newResult`
2. Count successes from `newResult`
3. 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()`, `numberOfSuccesses` equals the count of values >= threshold in `result`
- Test with default threshold (5) and custom threshold
- Test that `result` list has correct size (matches `numberOfDice`)
- Test the `countSuccesses` extension function directly
## AC Verification Checklist
1. [ ] `numberOfSuccesses` is computed from newly rolled values (not stale result list)
2. [ ] Unit test verifying correct success count after `.roll()`