update view, still work to do

This commit is contained in:
Rory Hinnen
2026-09-08 17:49:59 -05:00
parent 241a753879
commit b1d4094f78
9 changed files with 201 additions and 204 deletions
+51 -11
View File
@@ -227,20 +227,30 @@ struct RerollTests {
#expect(roll.hitHasRerolled == true)
}
@Test("applyReroll: guard blocks second call")
func applyRerollRespectsFlagAlreadySet() {
@Test("applyReroll: re-applying restores snapshot and rerolls with new mode")
func applyRerollChangeModeRestoresSnapshot() {
let roll = Roll()
roll.state = .hit
roll.hitCutoff = .four
roll.hitRerollMode = .ones
roll.dice.one = 3; roll.dice.six = 2
roll.total = 5
// First reroll: reroll the 3 ones
roll.applyReroll()
#expect(roll.hitHasRerolled == true)
#expect(roll.preRerollDice != nil)
let afterFirst = roll.dice.one + roll.dice.two + roll.dice.three +
roll.dice.four + roll.dice.five + roll.dice.six
#expect(afterFirst == 5)
// Switch to 'all' mode — should restore snapshot then reroll all
roll.hitRerollMode = .all
roll.hitHasRerolled = true // simulate already used
roll.dice.one = 5 // known state
roll.applyReroll() // should be blocked by guard
#expect(roll.dice.one == 5)
#expect(roll.dice.two == 0)
#expect(roll.dice.three == 0)
#expect(roll.dice.four == 0)
#expect(roll.dice.five == 0)
#expect(roll.dice.six == 0)
roll.applyReroll()
let afterSecond = roll.dice.one + roll.dice.two + roll.dice.three +
roll.dice.four + roll.dice.five + roll.dice.six
#expect(afterSecond == 5)
#expect(roll.hitHasRerolled == true)
}
@Test("applyReroll: only sets flag for the active phase")
@@ -269,6 +279,36 @@ struct RerollTests {
#expect(roll.dice.six >= 2) // dice above cutoff are untouched; rerolls may also produce sixes
}
@Test("undoReroll: restores dice and clears flag")
func undoRerollRestoresDice() {
let roll = Roll()
roll.state = .hit
roll.hitCutoff = .four
roll.hitRerollMode = .ones
roll.dice.one = 3; roll.dice.six = 2
roll.total = 5
roll.applyReroll()
#expect(roll.hitHasRerolled == true)
roll.undoReroll()
#expect(roll.hitHasRerolled == false)
#expect(roll.preRerollDice == nil)
// Dice should be restored to original state
#expect(roll.dice.one == 3)
#expect(roll.dice.six == 2)
}
@Test("undoReroll: no-op when no reroll has been applied")
func undoRerollNoop() {
let roll = Roll()
roll.state = .hit
roll.dice.one = 3
roll.undoReroll() // nothing to undo
#expect(roll.dice.one == 3)
#expect(roll.hitHasRerolled == false)
}
@Test("resetPool: clears hitHasRerolled flag")
func resetPoolClearsFlag() {
let roll = Roll()