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

This commit was merged in pull request #39.
This commit is contained in:
2026-03-13 12:22:57 +01:00
parent 3834c4fc8e
commit d08cc83348
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()`