-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathphysics_test.go
48 lines (37 loc) · 1.11 KB
/
physics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"testing"
"github.com/go-gl/mathgl/mgl32"
)
func TestColHandCheckPlayerPos(t *testing.T) {
level, err := newLevel("test3.wwl")
if err != nil {
panic(err)
}
var want = struct {
noCollision bool
oClosestPoint mgl32.Vec2
oShortestDistance float32
}{false, mgl32.Vec2{139, 109.52989}, 3.3006592}
noCollision, oClosestPoint, oShortestDistance := colHandCheckPlayerPos(&level.polygon, 135.69934, 109.52989)
if noCollision != want.noCollision ||
!oClosestPoint.ApproxEqual(want.oClosestPoint) ||
!mgl32.FloatEqual(oShortestDistance, want.oShortestDistance) {
t.Fatalf("colHandCheckPlayerPos returned unexpected results\ngot:\n%v %v %v\nwant:\n%v\n", noCollision, oClosestPoint, oShortestDistance, want)
}
}
var (
noCollision bool
oClosestPoint mgl32.Vec2
oShortestDistance float32
)
func BenchmarkColHandCheckPlayerPos(b *testing.B) {
level, err := newLevel("test3.wwl")
if err != nil {
panic(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
noCollision, oClosestPoint, oShortestDistance = colHandCheckPlayerPos(&level.polygon, 135.69934, 109.52989)
}
}