-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry_movement_test.go
97 lines (91 loc) · 1.42 KB
/
geometry_movement_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMovingDistance(t *testing.T) {
tests := []struct {
name string
speed float64
acc float64
time float64
want float64
}{
{
name: `speed`,
speed: 10,
time: 5,
want: 50,
},
{
name: `acc`,
acc: 10,
time: 5,
want: 125,
},
{
name: `speed and acc`,
speed: 10,
acc: 10,
time: 5,
want: 175,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, MovingDistance(tc.speed, tc.acc, tc.time))
})
}
}
func TestMovingVector(t *testing.T) {
tests := []struct {
name string
angle float64
power float64
want Point
}{
{
name: `top`,
angle: angleForward,
power: 4,
want: Point{0, 4},
},
{
name: `right`,
angle: angleRight,
power: 4,
want: Point{4, 0},
},
{
name: `left`,
angle: angleLeft,
power: 4,
want: Point{-4, 0},
},
{
name: `back`,
angle: angleBack,
power: 4,
want: Point{0, -4},
},
{
name: `top left`,
angle: 45,
power: 4,
want: Point{-2.82, 2.828},
},
{
name: `top right`,
angle: -45,
power: 4,
want: Point{2.82, 2.828},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
mv := MovingVector(tc.angle, tc.power)
assert.InDelta(t, tc.want.X, mv.X, 0.1)
assert.InDelta(t, tc.want.Y, mv.Y, 0.1)
})
}
}