Browse Source

added tests for last commit (ProbeResult.Type)

master
Stephen McQuay 6 years ago
parent
commit
a57903d81c
1 changed files with 60 additions and 0 deletions
  1. +60
    -0
      robot_test.go

+ 60
- 0
robot_test.go View File

@ -2,10 +2,15 @@ package main
import (
v "bitbucket.org/hackerbots/vector"
"log"
"math"
"testing"
)
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}
func TestCollision(t *testing.T) {
tests := []struct {
g game
@ -89,3 +94,58 @@ func TestCollision(t *testing.T) {
func TestBotBotCollisions(t *testing.T) {
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)
}
}

Loading…
Cancel
Save