Files
zombie/models/zombie_test.go

254 lines
4.4 KiB
Go

package models
import (
"reflect"
"testing"
)
func TestZombie_MoveUp(t *testing.T) {
type fields struct {
GridSize int
Coordinate Coordinate
}
tests := []struct {
name string
fields fields
expectedCoordinate Coordinate
}{
{
"can handle move up normally",
fields{
4,
Coordinate{
2,
2,
},
},
Coordinate{
XAxis: 2,
YAxis: 1,
},
},
{
"can handle move up when currently at the top edge",
fields{
8,
Coordinate{
2,
0,
},
},
Coordinate{
XAxis: 2,
YAxis: 7,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
zombie := &Zombie{
GridSize: tt.fields.GridSize,
Coordinate: tt.fields.Coordinate,
}
zombie.MoveUp()
if !reflect.DeepEqual(zombie.Coordinate, tt.expectedCoordinate) {
t.Errorf("zombie's coordindate is not matched, expected %v but got %v", tt.expectedCoordinate, zombie.Coordinate)
}
})
}
}
func TestZombie_MoveDown(t *testing.T) {
type fields struct {
GridSize int
Coordinate Coordinate
}
tests := []struct {
name string
fields fields
expectedCoordinate Coordinate
}{
{
"can handle move down normally",
fields{
4,
Coordinate{
2,
2,
},
},
Coordinate{
XAxis: 2,
YAxis: 3,
},
},
{
"can handle move down when currently at the bottom edge",
fields{
8,
Coordinate{
2,
7,
},
},
Coordinate{
XAxis: 2,
YAxis: 0,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
zombie := &Zombie{
GridSize: tt.fields.GridSize,
Coordinate: tt.fields.Coordinate,
}
zombie.MoveDown()
if !reflect.DeepEqual(zombie.Coordinate, tt.expectedCoordinate) {
t.Errorf("zombie's coordindate is not matched, expected %v but got %v", tt.expectedCoordinate, zombie.Coordinate)
}
})
}
}
func TestZombie_MoveLeft(t *testing.T) {
type fields struct {
GridSize int
Coordinate Coordinate
}
tests := []struct {
name string
fields fields
expectedCoordinate Coordinate
}{
{
"can handle move left normally",
fields{
4,
Coordinate{
2,
2,
},
},
Coordinate{
XAxis: 1,
YAxis: 2,
},
},
{
"can handle move left when currently at the left edge",
fields{
8,
Coordinate{
0,
2,
},
},
Coordinate{
XAxis: 7,
YAxis: 2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
zombie := &Zombie{
GridSize: tt.fields.GridSize,
Coordinate: tt.fields.Coordinate,
}
zombie.MoveLeft()
if !reflect.DeepEqual(zombie.Coordinate, tt.expectedCoordinate) {
t.Errorf("zombie's coordindate is not matched, expected %v but got %v", tt.expectedCoordinate, zombie.Coordinate)
}
})
}
}
func TestZombie_MoveRight(t *testing.T) {
type fields struct {
GridSize int
Coordinate Coordinate
}
tests := []struct {
name string
fields fields
expectedCoordinate Coordinate
}{
{
"can handle move right normally",
fields{
4,
Coordinate{
2,
2,
},
},
Coordinate{
XAxis: 3,
YAxis: 2,
},
},
{
"can handle move right when currently at the right edge",
fields{
8,
Coordinate{
7,
2,
},
},
Coordinate{
XAxis: 0,
YAxis: 2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
zombie := &Zombie{
GridSize: tt.fields.GridSize,
Coordinate: tt.fields.Coordinate,
}
zombie.MoveRight()
if !reflect.DeepEqual(zombie.Coordinate, tt.expectedCoordinate) {
t.Errorf("zombie's coordindate is not matched, expected %v but got %v", tt.expectedCoordinate, zombie.Coordinate)
}
})
}
}
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)
}
})
}
}