28 lines
1.2 KiB
Markdown
28 lines
1.2 KiB
Markdown
# 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()`
|