all features implemented

This commit is contained in:
Rory Hinnen
2026-09-07 15:27:33 -05:00
parent ac4d4a670a
commit 2a6130ba8e
64 changed files with 691 additions and 340 deletions
@@ -0,0 +1,71 @@
import Testing
@testable import DieHammerEngine
@Suite("Dice")
struct DiceTests {
func oneEach() -> Dice {
var d = Dice()
d.one = 1; d.two = 1; d.three = 1; d.four = 1; d.five = 1; d.six = 1
return d
}
@Test("roll preserves total count")
func rollCount() {
var d = Dice()
d.roll(howMany: 10)
let total = d.one + d.two + d.three + d.four + d.five + d.six
#expect(total == 10)
}
@Test("hit counts dice at or above cutoff (no modifier)")
func hitNoModifier() {
let d = oneEach()
#expect(d.hit(cutoff: 4, modifier: 0) == 3) // 4,5,6
#expect(d.hit(cutoff: 6, modifier: 0) == 1) // 6 only
}
@Test("armour: AP worsens save (higher switch value = more failures)")
func armourAP() {
let d = oneEach()
// 3+ save, AP-1 → effective 4+: dice 1,2,3 fail = 3
#expect(d.armour(save: 3, armourPenetration: 1, invulnerable: false) == 3)
}
@Test("armour: invulnerable ignores AP")
func armourInvulnerable() {
let d = oneEach()
let withInvuln = d.armour(save: 4, armourPenetration: 5, invulnerable: true)
let noAP = d.armour(save: 4, armourPenetration: 0, invulnerable: false)
#expect(withInvuln == noAP)
}
}
@Suite("WoundCutoff")
struct WoundCutoffTests {
@Test("S double T: wound on 2+")
func doubleStrength() {
#expect(woundCutoff(strength: 10, toughness: 5) == 2)
}
@Test("S greater than T: wound on 3+")
func strengthHigher() {
#expect(woundCutoff(strength: 7, toughness: 5) == 3)
}
@Test("S equals T: wound on 4+")
func equal() {
#expect(woundCutoff(strength: 5, toughness: 5) == 4)
}
@Test("T greater than S: wound on 5+")
func toughnessHigher() {
#expect(woundCutoff(strength: 3, toughness: 5) == 5)
}
@Test("T double S: wound on 6+")
func doubleToughness() {
#expect(woundCutoff(strength: 2, toughness: 5) == 6)
}
}