Files
gogobee/internal/plugin/dnd_test.go
prosolis 5ef10e35dc Phase 5b: player power floor + Phase-3 winners shipped to live
Closes the 'fairly breezy with some death' target the user picked
for Phase 5. Five-piece ship; Phase 1 matrix lands T1 88%, T2 74%,
T4 72%, T5 ~57% in or above band. T3 remains the design hump at
~45% (manor 39, underforge 47) — Wraith promotion to elite was
already done in Phase 4-B, the remaining standard-pool deaths are
the irreducible part of T3.

Pieces:
  1. computeMaxHP × 1.5 (phase5BHPMult in dnd.go). Uniform across
     class/level so the class-balance harness's in-tier parity
     assertion stays green. Bootstrap (bootstrap_phase5b_hp.go)
     refreshes hp_max for existing characters at startup;
     idempotent via db.JobCompleted. hp_current is bumped by the
     same delta so a full-HP character stays at full.
  2. applyPhase5BPlayerFloor (dnd_combat.go): +3 AC, +3 AttackBonus,
     +3 weapon.MagicBonus (damage). Applied at the END of
     applyDnDEquipmentLayer (after computeArmorAC's AC override)
     and inside buildHarnessPlayer so live and harness measurement
     match.
  3. Elite bracket 19 → 23 (resolveCombatInterrupt). Case order
     puts Elite (≥23) before Patrol (≥22) so a 23+ total prefers
     the single dangerous fight. Elite is now effectively a
     high-threat event reachable only via the +1-per-20-threat-
     above-40 mod — Phase 4-B's elite-pool monsters still appear,
     just less often.
  4. dailyThreatDrift base 3 → 1. Slows the threat clock so
     players have the days they need before threat tips zones
     into the new 23+ elite band.
  5. applyDailyBurn default → 50% (phase5BDailyBurnRatePct). Also
     applied in the temporal-override branch in
     dnd_expedition_cycle.go so tidal / unraveling days scale by
     the same 0.5× — otherwise those days would be
     disproportionately harsh against the new baseline.

The harness's expedition_balance.go reads phase5BDailyBurnRatePct
as the default-burn fallback when the override knob is zero, so
Phase 1 matrix measurements now reflect what live players
experience.

Test debt: 13 pinned-numbers unit tests across combat_stats_test,
dnd_test, dnd_xp_test, dnd_equipment_profiles_test,
dnd_expedition_supplies_test, dnd_expedition_cycle_test,
dnd_expedition_extract_test, dnd_expedition_region_cmd_test,
dnd_expedition_combat_test, dnd_expedition_threat_test,
dnd_expedition_temporal_test, expedition_balance_test were
pinning pre-Phase-5-B baselines; updated with comments noting
the cause. Class-balance suite stayed green (uniform buff
preserves spread).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 12:11:27 -07:00

265 lines
7.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package plugin
import (
"testing"
)
func TestAbilityModifier(t *testing.T) {
cases := []struct {
score, want int
}{
{1, -5},
{8, -1},
{9, -1},
{10, 0},
{11, 0},
{12, 1},
{13, 1},
{14, 2},
{15, 2},
{16, 3},
{18, 4},
{20, 5},
}
for _, c := range cases {
got := abilityModifier(c.score)
if got != c.want {
t.Errorf("abilityModifier(%d) = %d, want %d", c.score, got, c.want)
}
}
}
func TestIsStandardArray(t *testing.T) {
good := [][]int{
{15, 14, 13, 12, 10, 8},
{8, 10, 12, 13, 14, 15},
{14, 8, 15, 10, 13, 12},
}
for _, g := range good {
var arr [6]int
copy(arr[:], g)
if !isStandardArray(arr) {
t.Errorf("isStandardArray(%v) = false, want true", g)
}
}
bad := [][]int{
{15, 15, 13, 12, 10, 8}, // duplicate 15
{16, 14, 13, 12, 10, 8}, // out-of-range
{15, 14, 13, 12, 10, 9}, // 9 instead of 8
{15, 14, 13, 12, 11, 8}, // 11 instead of 10
}
for _, ba := range bad {
var arr [6]int
copy(arr[:], ba)
if isStandardArray(arr) {
t.Errorf("isStandardArray(%v) = true, want false", ba)
}
}
}
func TestComputeMaxHP_FighterLevel1(t *testing.T) {
// Fighter d10, CON +2 → L1 raw HP = 10 + 2 = 12; Phase 5-B
// multiplies by phase5BHPMult (1.5, rounded), so → 18.
got := computeMaxHP(ClassFighter, 2, 1)
if got != 18 {
t.Errorf("Fighter L1 (CON+2) = %d, want 18 (12 raw × phase5BHPMult)", got)
}
}
func TestComputeMaxHP_MageLevel5(t *testing.T) {
// Mage d6, CON +1
// L1: 6 + 1 = 7
// L2-5: 4 levels × (avg 4 + 1) = 4 × 5 = 20
// Raw total: 27; Phase 5-B: 27 × 1.5 = 40.5 → 41 (round half-up).
got := computeMaxHP(ClassMage, 1, 5)
if got != 41 {
t.Errorf("Mage L5 (CON+1) = %d, want 41 (27 raw × phase5BHPMult)", got)
}
}
func TestComputeMaxHP_FloorAt1(t *testing.T) {
// Pathological: very negative CON, low level → still ≥1 per level
got := computeMaxHP(ClassMage, -5, 1)
if got < 1 {
t.Errorf("HP floor violated: got %d", got)
}
}
func TestComputeAC(t *testing.T) {
cases := []struct {
class DnDClass
dexMod int
want int
}{
{ClassFighter, 0, 16}, // 10 + 0 + 6
{ClassFighter, 2, 18}, // 10 + 2 + 6
{ClassRogue, 3, 14}, // 10 + 3 + 1
{ClassMage, 0, 10}, // 10 + 0 + 0
{ClassCleric, 1, 14}, // 10 + 1 + 3
{ClassRanger, 2, 15}, // 10 + 2 + 3
}
for _, c := range cases {
got := computeAC(c.class, c.dexMod)
if got != c.want {
t.Errorf("computeAC(%s, dex%+d) = %d, want %d", c.class, c.dexMod, got, c.want)
}
}
}
func TestApplyRaceMods(t *testing.T) {
// Elf: STR +0, DEX +3, CON -1, INT +2, WIS +3, CHA +0
base := [6]int{10, 10, 10, 10, 10, 10}
got := applyRaceMods(RaceElf, base)
want := [6]int{10, 13, 9, 12, 13, 10}
if got != want {
t.Errorf("applyRaceMods(Elf) = %v, want %v", got, want)
}
// Orc: STR +6, DEX -1, CON +3, INT -1, WIS -1, CHA +0
got = applyRaceMods(RaceOrc, base)
want = [6]int{16, 9, 13, 9, 9, 10}
if got != want {
t.Errorf("applyRaceMods(Orc) = %v, want %v", got, want)
}
}
// TestRaceBalance runs the weighted balance pass and logs the report.
// Standard Human baseline is 6.0 under every class; a race's best-fit
// score is its realistic effective-power ceiling. The assertion is a
// generous guard rail — see classStatWeights for the model.
func TestRaceBalance(t *testing.T) {
report := computeRaceBalance()
t.Logf("weighted race-balance pass (Human baseline = %.1f)", raceBalanceBaseline)
t.Logf("%-10s %-9s %6s %-9s %6s %6s %+6s",
"race", "best-fit", "score", "worst-fit", "score", "avg", "Δ")
for _, rb := range report {
t.Logf("%-10s %-9s %6.2f %-9s %6.2f %6.2f %+6.2f",
rb.Race, rb.BestClass, rb.BestScore,
rb.WorstClass, rb.WorstScore, rb.AvgScore, rb.Delta())
}
// Balance rule: equal *average* power. Every race's mean score across
// all playable classes must land within tolerance of the Human
// baseline. Best-fit/worst-fit spread is intentional race identity —
// a spiky race trades a higher ceiling for a lower floor — so only
// the average is asserted.
const tolerance = 0.5
for _, rb := range report {
if d := rb.AvgScore - raceBalanceBaseline; d < -tolerance || d > tolerance {
t.Errorf("%s avg %.2f is %.2f off the %.1f baseline (tolerance %.1f)",
rb.Race, rb.AvgScore, d, raceBalanceBaseline, tolerance)
}
}
}
func TestParseRaceClass(t *testing.T) {
if r, ok := parseRace("Elf"); !ok || r != RaceElf {
t.Errorf("parseRace(Elf) = %v, %v", r, ok)
}
if r, ok := parseRace("half-elf"); !ok || r != RaceHalfElf {
t.Errorf("parseRace(half-elf) = %v, %v", r, ok)
}
if _, ok := parseRace("dragonborn"); ok {
t.Errorf("parseRace(dragonborn) = ok, want false")
}
if c, ok := parseClass("Fighter"); !ok || c != ClassFighter {
t.Errorf("parseClass(Fighter) = %v, %v", c, ok)
}
if _, ok := parseClass("monk"); ok {
t.Errorf("parseClass(monk) = ok, want false")
}
}
func TestStatsAssigned(t *testing.T) {
defaultC := &DnDCharacter{STR: 8, DEX: 8, CON: 8, INT: 8, WIS: 8, CHA: 8}
if statsAssigned(defaultC) {
t.Error("statsAssigned(all-8s) = true, want false")
}
withStats := &DnDCharacter{STR: 15, DEX: 14, CON: 13, INT: 12, WIS: 10, CHA: 8}
if !statsAssigned(withStats) {
t.Error("statsAssigned(real stats) = false, want true")
}
}
func TestParseStatsArg(t *testing.T) {
want := [6]int{15, 14, 13, 12, 10, 8}
cases := []string{
"15 14 13 12 10 8",
"15, 14, 13, 12, 10, 8",
"(15, 14, 13, 12, 10, 8)",
"[15,14,13,12,10,8]",
"{15 14 13 12 10 8}",
" 15,14 ,13, 12 ,10, 8 ",
}
for _, in := range cases {
got, err := parseStatsArg(in)
if err != nil {
t.Errorf("parseStatsArg(%q) returned error: %v", in, err)
continue
}
if got != want {
t.Errorf("parseStatsArg(%q) = %v, want %v", in, got, want)
}
}
bad := []string{
"", // empty
"15 14 13 12 10", // 5 numbers
"15 14 13 12 10 8 7", // 7 numbers
"15 14 13 12 10 abc", // non-number
"banana", // garbage
}
for _, in := range bad {
if _, err := parseStatsArg(in); err == nil {
t.Errorf("parseStatsArg(%q) should have errored", in)
}
}
// A different permutation should still parse and just return the
// numbers in order — validation against the standard array is
// a separate concern (isStandardArray).
got, err := parseStatsArg("8, 10, 12, 13, 14, 15")
if err != nil {
t.Fatal(err)
}
if got != [6]int{8, 10, 12, 13, 14, 15} {
t.Errorf("permutation order not preserved: %v", got)
}
}
func TestDnDLevelFromCombatLevel(t *testing.T) {
cases := []struct{ combat, want int }{
{0, 1}, // floor
{1, 1},
{4, 1},
{5, 1},
{9, 1},
{10, 2},
{15, 3},
{20, 4}, // nonk
{24, 4}, // quack
{25, 5},
{28, 5}, // prosolis
{30, 6},
{45, 9},
{49, 9}, // holymachina
{50, 10},
{99, 19},
{100, 20}, // clamp
{500, 20}, // clamp
}
for _, c := range cases {
got := dndLevelFromCombatLevel(c.combat)
if got != c.want {
t.Errorf("dndLevelFromCombatLevel(%d) = %d, want %d", c.combat, got, c.want)
}
}
}
func TestModifiersOnCharacter(t *testing.T) {
c := &DnDCharacter{STR: 16, DEX: 12, CON: 14, INT: 10, WIS: 8, CHA: 18}
mods := c.Modifiers()
want := [6]int{3, 1, 2, 0, -1, 4}
if mods != want {
t.Errorf("Modifiers() = %v, want %v", mods, want)
}
}