gochecknoglobals: all 37 package-level tables consolidated into the gameData struct (game/tables.go), built by newGameData() and carried on RogueGame as g.data (set in NewGame and Restore). ObjectKind Glyph()/objectKindForGlyph are now switches; the table-reading subtype Stringer methods are gone; isMagic is a RogueGame method. goconst: repeated words named (potionName/scrollName/ringName/goldName in object.go, wandName/staffName in sticks.go, ripWall in tables.go). exhaustive, testpackage: disabled in .golangci.yml with sneak's approval (2026-07-07). Also reverts misspell's silent corruption of the "ther" scroll-name syllable (it had become "there", changing generated scroll names vs C). Remaining red: cyclop/gocognit/nestif until refactor step 7; mnd awaits a ruling. TODO.md rotated; MEMORY.md lint notes updated.
102 lines
2.3 KiB
Go
102 lines
2.3 KiB
Go
package game
|
|
|
|
import "testing"
|
|
|
|
// badcheck from init.c: every probability table must sum to exactly 100.
|
|
func TestProbabilitiesSumTo100(t *testing.T) {
|
|
sum := func(info []ObjInfo) int {
|
|
s := 0
|
|
for _, oi := range info {
|
|
s += oi.Prob
|
|
}
|
|
|
|
return s
|
|
}
|
|
|
|
data := newGameData()
|
|
|
|
tables := map[string][]ObjInfo{
|
|
"things": data.baseThings[:],
|
|
"potions": data.basePotInfo[:],
|
|
"scrolls": data.baseScrInfo[:],
|
|
"rings": data.baseRingInfo[:],
|
|
"sticks": data.baseWsInfo[:],
|
|
"weapons": data.baseWeapInfo[:NumWeaponTypes], // excludes the flame entry
|
|
"armor": data.baseArmInfo[:],
|
|
}
|
|
for name, tab := range tables {
|
|
if s := sum(tab); s != 100 {
|
|
t.Errorf("bad percentages for %s: sum = %d, want 100", name, s)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInitProbsCumulative(t *testing.T) {
|
|
g := NewGame(Config{Seed: 1})
|
|
|
|
last := g.Items.Potions[NumPotionTypes-1].Prob
|
|
if last != 100 {
|
|
t.Errorf("cumulative potion probability ends at %d, want 100", last)
|
|
}
|
|
|
|
for i := PotionKind(1); i < NumPotionTypes; i++ {
|
|
if g.Items.Potions[i].Prob < g.Items.Potions[i-1].Prob {
|
|
t.Errorf("potion probs not nondecreasing at %d", i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewGameRandomizesAppearances(t *testing.T) {
|
|
g := NewGame(Config{Seed: 12345})
|
|
seen := map[string]bool{}
|
|
|
|
for i, c := range g.Items.PotColors {
|
|
if c == "" {
|
|
t.Fatalf("potion %d has no color", i)
|
|
}
|
|
|
|
if seen[c] {
|
|
t.Errorf("potion color %q assigned twice", c)
|
|
}
|
|
|
|
seen[c] = true
|
|
}
|
|
|
|
for i, n := range g.Items.ScrNames {
|
|
if n == "" {
|
|
t.Fatalf("scroll %d has no name", i)
|
|
}
|
|
|
|
if len(n) > MaxNameLen+1 {
|
|
t.Errorf("scroll name %q longer than C buffer allows", n)
|
|
}
|
|
}
|
|
|
|
for i := range g.Items.WandType {
|
|
if g.Items.WandType[i] != "wand" && g.Items.WandType[i] != "staff" {
|
|
t.Errorf("stick %d has type %q", i, g.Items.WandType[i])
|
|
}
|
|
|
|
if g.Items.WandMade[i] == "" {
|
|
t.Errorf("stick %d has no material", i)
|
|
}
|
|
}
|
|
|
|
// Determinism: same seed, same appearances.
|
|
h := NewGame(Config{Seed: 12345})
|
|
if h.Items != g.Items {
|
|
t.Error("two games with the same seed produced different item lore")
|
|
}
|
|
}
|
|
|
|
func TestMonsterTable(t *testing.T) {
|
|
data := newGameData()
|
|
if data.monsterTable[0].Name != "aquator" || data.monsterTable[25].Name != "zombie" {
|
|
t.Error("monster table order broken")
|
|
}
|
|
|
|
if data.monsterTable['D'-'A'].Name != "dragon" {
|
|
t.Error("letter indexing broken")
|
|
}
|
|
}
|