-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxisdevice_test.go
58 lines (42 loc) · 1.8 KB
/
axisdevice_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
package inputeventsubsystem
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCorrectAxis(t *testing.T) {
t.Run("0-255 range deadzone 0", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 255, Flat: 0}}, true, -1)
v := a.CorrectAxis(ABS_X, 100)
assert.Equal(t, int32(-7068), v)
})
t.Run("0-255 range deadzone override 10", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 255, Flat: 0}}, true, 10)
v := a.CorrectAxis(ABS_X, 10)
assert.Equal(t, int32(-32767), v)
})
t.Run("-2 - 2 range deadzone override 1", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: -2, Maximum: 2, Flat: 0}}, true, 1)
v := a.CorrectAxis(ABS_X, 10)
assert.Equal(t, int32(0), v)
})
t.Run("0-0 range deadzone 0", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 0, Flat: 0}}, true, -1)
v := a.CorrectAxis(ABS_X, 1000)
assert.Equal(t, int32(1000), v)
})
t.Run("0-255 range deadzone off", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 0, Flat: 0}}, false, -1)
v := a.CorrectAxis(ABS_X, 100)
assert.Equal(t, int32(99), v)
})
t.Run("0-255 range deadzone override 10 divide 255", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 255, Flat: 0}}, true, 0)
v := a.CorrectAxis(ABS_X, 100)/255 + 127
assert.Equal(t, int32(100), v)
})
t.Run("0-255 range deadzone offs", func(t *testing.T) {
a := CreateAxisDeviceFromAbsInfo(nil, map[int]AbsInfo{ABS_X: {Minimum: 0, Maximum: 255, Flat: 0}}, false, 0)
v := a.CorrectAxis(ABS_X, 0)
assert.Equal(t, int32(-32767), v)
})
}