Decompose test functions to clear complexity findings (step 7)
TestSaveRestoreRoundTrip, TestNewGameRandomizesAppearances, and TestNewLevelInvariants split their assertion blocks into t.Helper() sub-checks. The lint run is now completely clean (0 issues).
This commit is contained in:
@@ -48,6 +48,22 @@ func TestInitProbsCumulative(t *testing.T) {
|
||||
|
||||
func TestNewGameRandomizesAppearances(t *testing.T) {
|
||||
g := NewGame(Config{Seed: 12345})
|
||||
|
||||
checkPotionColors(t, g)
|
||||
checkScrollNames(t, g)
|
||||
checkWandMaterials(t, g)
|
||||
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
|
||||
// checkPotionColors verifies every potion has a distinct color.
|
||||
func checkPotionColors(t *testing.T, g *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
seen := map[string]bool{}
|
||||
|
||||
for i, c := range g.Items.PotColors {
|
||||
@@ -61,6 +77,12 @@ func TestNewGameRandomizesAppearances(t *testing.T) {
|
||||
|
||||
seen[c] = true
|
||||
}
|
||||
}
|
||||
|
||||
// checkScrollNames verifies every scroll has a name within the C buffer
|
||||
// limit.
|
||||
func checkScrollNames(t *testing.T, g *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
for i, n := range g.Items.ScrNames {
|
||||
if n == "" {
|
||||
@@ -71,9 +93,15 @@ func TestNewGameRandomizesAppearances(t *testing.T) {
|
||||
t.Errorf("scroll name %q longer than C buffer allows", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkWandMaterials verifies every stick has a wand/staff type and a
|
||||
// material.
|
||||
func checkWandMaterials(t *testing.T, g *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
for i := range g.Items.WandType {
|
||||
if g.Items.WandType[i] != "wand" && g.Items.WandType[i] != "staff" {
|
||||
if g.Items.WandType[i] != wandName && g.Items.WandType[i] != staffName {
|
||||
t.Errorf("stick %d has type %q", i, g.Items.WandType[i])
|
||||
}
|
||||
|
||||
@@ -81,12 +109,6 @@ func TestNewGameRandomizesAppearances(t *testing.T) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user