package input import ( "testing" fightinfo "blazing/logic/service/fight/info" "blazing/modules/player/model" ) func TestLivingTeammatesFiltersSelfAndDeadSlots(t *testing.T) { owner := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 10}}}} aliveMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 5}}}} deadMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}} team := []*Input{owner, aliveMate, deadMate} owner.Team = team aliveMate.Team = team deadMate.Team = team teammates := owner.LivingTeammates() if len(teammates) != 1 { t.Fatalf("expected 1 living teammate, got %d", len(teammates)) } if teammates[0] != aliveMate { t.Fatalf("expected alive teammate to be returned") } if owner.HasLivingTeammate() != true { t.Fatalf("expected owner to detect living teammate") } } func TestTeamSlotIndexKeepsOriginalSlot(t *testing.T) { first := &Input{} second := &Input{} third := &Input{} team := []*Input{first, second, third} first.Team = team second.Team = team third.Team = team if got := third.TeamSlotIndex(); got != 2 { t.Fatalf("expected slot index 2, got %d", got) } } func TestRandomOpponentSlotIndexPrefersLivingTarget(t *testing.T) { owner := &Input{} deadOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}} liveOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 12}}}} owner.OppTeam = []*Input{deadOpp, liveOpp} if got := owner.RandomOpponentSlotIndex(); got != 1 { t.Fatalf("expected living opponent slot 1, got %d", got) } if got := owner.OpponentSlotAt(1); got != liveOpp { t.Fatalf("expected opponent slot 1 to return live opponent") } }