package zombie import ( "github.com/wahyd4/zombie/models" "reflect" "testing" ) func TestApplication_Run(t *testing.T) { type fields struct { GridSize int Creatures []*models.Creature Commands []MoveCommand CurrentZombie *models.Zombie NextZombie *TransformedZombie FinishedZombies []*models.Zombie Score int } tests := []struct { name string fields fields wantFinishedZombies []*models.Zombie wantScore int }{ { "can run a simple command", fields{ GridSize: 4, Creatures: []*models.Creature{ &models.Creature{ Coordinate: models.Coordinate{ XAxis: 1, YAxis: 1, }, }, }, Commands: []MoveCommand{ &MoveUpCommand{}, }, CurrentZombie: &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 3, YAxis: 3, }, }, NextZombie: nil, FinishedZombies: nil, Score: 0, }, []*models.Zombie{ &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 3, YAxis: 2, }, }, }, 0, }, { "can run some more commands", fields{ GridSize: 4, Creatures: []*models.Creature{ &models.Creature{ Coordinate: models.Coordinate{ XAxis: 0, YAxis: 1, }, }, &models.Creature{ Coordinate: models.Coordinate{ XAxis: 1, YAxis: 2, }, }, &models.Creature{ Coordinate: models.Coordinate{ XAxis: 3, YAxis: 1, }, }, }, Commands: []MoveCommand{ &MoveDownCommand{}, &MoveLeftCommand{}, &MoveUpCommand{}, &MoveUpCommand{}, &MoveRightCommand{}, &MoveRightCommand{}, }, CurrentZombie: &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 2, YAxis: 1, }, }, NextZombie: nil, FinishedZombies: nil, Score: 0, }, []*models.Zombie{ &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 3, YAxis: 0, }, }, &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 2, YAxis: 1, }, }, &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 1, YAxis: 0, }, }, &models.Zombie{ GridSize: 4, Coordinate: models.Coordinate{ XAxis: 0, YAxis: 0, }, }, }, 3, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { app := &Application{ gridSize: tt.fields.GridSize, creatures: tt.fields.Creatures, commands: tt.fields.Commands, currentZombie: tt.fields.CurrentZombie, nextZombie: tt.fields.NextZombie, finishedZombies: tt.fields.FinishedZombies, score: tt.fields.Score, } app.Run() if ok := reflect.DeepEqual(tt.wantFinishedZombies, app.finishedZombies); !ok { t.Errorf("expected wantFinishedZombies to be %v but got %v", tt.wantFinishedZombies, app.finishedZombies) } if ok := reflect.DeepEqual(tt.wantScore, app.score); !ok { t.Errorf("expected score to be %v but got %v", tt.wantScore, app.score) } }) } }