From a57903d81cfe1b02422a0db38202a270bbff6155 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Thu, 16 Jan 2014 23:45:17 -0800 Subject: [PATCH] added tests for last commit (ProbeResult.Type) --- robot_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/robot_test.go b/robot_test.go index 547c40e..4117edd 100644 --- a/robot_test.go +++ b/robot_test.go @@ -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) + } +}