diff --git a/models/zombie.go b/models/zombie.go index e2771b4..3a780cd 100644 --- a/models/zombie.go +++ b/models/zombie.go @@ -1,5 +1,7 @@ package models +import "fmt" + const ( minimumValueOnAXis = 0 ) @@ -56,6 +58,11 @@ func (zombie *Zombie) MoveRight() { zombie.Coordinate.XAxis-- } +// PrintLocation prints out the current coordinate +func (zombie *Zombie) PrintLocation() string { + return fmt.Sprintf("(%d,%d)", zombie.Coordinate.XAxis, zombie.Coordinate.YAxis) +} + func (zombie *Zombie) maxValueOnAxis() int { return zombie.GridSize - 1 } diff --git a/models/zombie_test.go b/models/zombie_test.go index 839c323..af512ea 100644 --- a/models/zombie_test.go +++ b/models/zombie_test.go @@ -111,7 +111,6 @@ func TestZombie_MoveDown(t *testing.T) { } } - func TestZombie_MoveLeft(t *testing.T) { type fields struct { GridSize int @@ -165,7 +164,6 @@ func TestZombie_MoveLeft(t *testing.T) { } } - func TestZombie_MoveRight(t *testing.T) { type fields struct { GridSize int @@ -218,3 +216,38 @@ func TestZombie_MoveRight(t *testing.T) { }) } } + +func TestZombie_PrintLocation(t *testing.T) { + type fields struct { + GridSize int + Coordinate Coordinate + } + tests := []struct { + name string + fields fields + want string + }{ + { + "can print out the zombie's location", + fields{ + 4, + Coordinate{ + 2, + 3, + }, + }, + "(2,3)", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + zombie := &Zombie{ + GridSize: tt.fields.GridSize, + Coordinate: tt.fields.Coordinate, + } + if got := zombie.PrintLocation(); got != tt.want { + t.Errorf("PrintLocation() = %v, want %v", got, tt.want) + } + }) + } +}