mirror of
https://github.com/wahyd4/zombie.git
synced 2026-08-09 04:35:54 +10:00
Add method to zombie to print out the current location
This commit is contained in:
@@ -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
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user