Add method to zombie to print out the current location

This commit is contained in:
2020-03-14 23:31:01 +11:00
parent 5b28579139
commit 7d78166490
2 changed files with 42 additions and 2 deletions
+7
View File
@@ -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
}
+35 -2
View File
@@ -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)
}
})
}
}