added tests for last commit (ProbeResult.Type)

This commit is contained in:
Stephen McQuay 2014-01-16 23:45:17 -08:00
parent 714ea669d2
commit a57903d81c

View File

@ -2,10 +2,15 @@ package main
import ( import (
v "bitbucket.org/hackerbots/vector" v "bitbucket.org/hackerbots/vector"
"log"
"math" "math"
"testing" "testing"
) )
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}
func TestCollision(t *testing.T) { func TestCollision(t *testing.T) {
tests := []struct { tests := []struct {
g game g game
@ -89,3 +94,58 @@ func TestCollision(t *testing.T) {
func TestBotBotCollisions(t *testing.T) { func TestBotBotCollisions(t *testing.T) {
t.Skip("NYI") t.Skip("NYI")
} }
func TestProbeResultType(t *testing.T) {
g := game{
width: 800,
height: 400,
obstacles: []Obstacle{
Obstacle{
Bounds: v.AABB2d{
v.Point2d{200, 100},
v.Point2d{300, 200},
},
},
Obstacle{
Bounds: v.AABB2d{
v.Point2d{400, 200},
v.Point2d{600, 300},
},
},
},
players: make(map[*player]bool),
}
r1 := Robot{
Position: v.Point2d{100, 100},
Probe: &v.Point2d{900, 350},
Id: "Bilbo's Bot",
}
p1 := player{
Robots: []*Robot{&r1},
Id: "bilbo",
}
r2 := Robot{
Position: v.Point2d{100, 200},
Probe: &v.Point2d{100, 90},
Id: "Frodo's Bot",
}
p2 := player{
Robots: []*Robot{&r2},
Id: "Frodo",
}
g.players[&p1] = true
g.players[&p2] = true
r1.Tick(&g)
r2.Tick(&g)
if r1.ProbeResult.Type != "obstacle" {
t.Errorf("incorrect probe type (expected obstacle, got %s)", r1.ProbeResult.Type)
}
if r2.ProbeResult.Type != "robot" {
t.Errorf("incorrect probe type (expected robot, got %s)", r1.ProbeResult.Type)
}
}