-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpoint_test.go
67 lines (57 loc) · 1.19 KB
/
point_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gease
import (
"math"
"testing"
"time"
"gioui.org/f32"
)
func TestPointEnds(t *testing.T) {
target := f32.Point{X: 100, Y: -55}
es := Point(f32.Point{})
es.Target(target)
// check initial position
if (es.V() != f32.Point{}) {
t.Error("expected initial")
}
// advance the simulation
tt := time.Now()
for !es.Step(tt) {
tt = tt.Add(time.Millisecond * 10)
}
// check the final position
pos := es.V()
if math.Abs(float64(pos.X-target.X)) > 0.15 || math.Abs(float64(pos.Y-target.Y)) > 0.15 {
t.Error("expected final position at end")
}
}
func BenchmarkPointStep(b *testing.B) {
es := Point(f32.Point{})
es.Target(f32.Point{X: 33, Y: 111})
b.ReportAllocs()
t := time.Now()
b.ResetTimer()
for i := 0; i < b.N; i++ {
es.Step(t)
t = t.Add(time.Millisecond)
}
// prevent compiler removing
b.StopTimer()
if es.V().X == -33 {
panic("cannot happen")
}
}
func BenchmarkPoint(b *testing.B) {
for i := 0; i < b.N; i++ {
es := Point(f32.Point{})
es.Target(f32.Point{X: 33, Y: 111})
// assuming 60 fps here
t := time.Now()
for !es.Step(t) {
t = t.Add(time.Millisecond * 17)
}
// prevent compiler removing
if es.V().X == 128 {
panic("cannot happen")
}
}
}