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:
@@ -39,6 +39,15 @@ func TestSaveRestoreRoundTrip(t *testing.T) {
|
||||
t.Error("save file not deleted on restore (C anti-restart rule)")
|
||||
}
|
||||
|
||||
checkRestoredState(t, g, h)
|
||||
checkRestoredMonsters(t, g, h)
|
||||
checkEquipmentAliasing(t, g, h)
|
||||
}
|
||||
|
||||
// checkRestoredState verifies the scalar state survived the round trip.
|
||||
func checkRestoredState(t *testing.T, g, h *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
if h.Player.Purse != 123 || h.Player.FoodLeft != 777 {
|
||||
t.Errorf("player state lost: purse=%d food=%d",
|
||||
h.Player.Purse, h.Player.FoodLeft)
|
||||
@@ -67,28 +76,41 @@ func TestSaveRestoreRoundTrip(t *testing.T) {
|
||||
if renderMap(h) != renderMap(g) {
|
||||
t.Error("restored level map differs")
|
||||
}
|
||||
}
|
||||
|
||||
// checkRestoredMonsters verifies the monster list and its pointer fixups
|
||||
// survived the round trip.
|
||||
func checkRestoredMonsters(t *testing.T, g, h *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
if len(h.Level.Monsters) != len(g.Level.Monsters) {
|
||||
t.Fatalf("monster count %d != %d",
|
||||
len(h.Level.Monsters), len(g.Level.Monsters))
|
||||
}
|
||||
|
||||
if len(g.Level.Monsters) > 0 {
|
||||
m := h.Level.Monsters[0]
|
||||
if m.Dest != &h.Player.Pos {
|
||||
t.Error("monster chase target not re-aliased to the hero")
|
||||
}
|
||||
|
||||
if h.Level.MonsterAt(m.Pos.Y, m.Pos.X) != m {
|
||||
t.Error("map monster index not rebuilt")
|
||||
}
|
||||
|
||||
if m.Room == nil {
|
||||
t.Error("monster room pointer not rebuilt")
|
||||
}
|
||||
if len(g.Level.Monsters) == 0 {
|
||||
return
|
||||
}
|
||||
// Equipment aliasing: the wielded mace must be the same *Object as the
|
||||
// one in the pack.
|
||||
|
||||
m := h.Level.Monsters[0]
|
||||
if m.Dest != &h.Player.Pos {
|
||||
t.Error("monster chase target not re-aliased to the hero")
|
||||
}
|
||||
|
||||
if h.Level.MonsterAt(m.Pos.Y, m.Pos.X) != m {
|
||||
t.Error("map monster index not rebuilt")
|
||||
}
|
||||
|
||||
if m.Room == nil {
|
||||
t.Error("monster room pointer not rebuilt")
|
||||
}
|
||||
}
|
||||
|
||||
// checkEquipmentAliasing verifies the wielded mace is the same *Object as
|
||||
// the one in the pack.
|
||||
func checkEquipmentAliasing(t *testing.T, g, h *RogueGame) {
|
||||
t.Helper()
|
||||
|
||||
st := g.snapshot()
|
||||
t.Logf("snapshot indices: weapon=%d armor=%d rings=%v packlen=%d",
|
||||
st.Player.CurWeapon, st.Player.CurArmor, st.Player.CurRing,
|
||||
|
||||
Reference in New Issue
Block a user