-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_test.go
73 lines (58 loc) · 1.46 KB
/
controller_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
// (c) 2022 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package pi_test
import (
"testing"
"github.com/elgopher/pi"
"github.com/stretchr/testify/assert"
)
var allButtons = []pi.Button{pi.Left, pi.Right, pi.Up, pi.Down, pi.O, pi.X}
func TestBtn(t *testing.T) {
testBtn(t, pi.Btn)
}
func testBtn(t *testing.T, btn func(pi.Button) bool) {
t.Run("should return false for invalid button", func(t *testing.T) {
assert.False(t, btn(-1))
assert.False(t, btn(6))
})
t.Run("should not panic", func(t *testing.T) {
for _, button := range allButtons {
btn(button)
}
})
}
func TestBtnPlayer(t *testing.T) {
testBtnPlayer(t, pi.BtnPlayer)
}
func testBtnPlayer(t *testing.T, btnPlayer func(pi.Button, int) bool) {
testBtn(t, func(b pi.Button) bool {
return btnPlayer(b, 0)
})
t.Run("should return false for invalid player", func(t *testing.T) {
assert.False(t, btnPlayer(pi.X, -1))
assert.False(t, btnPlayer(pi.X, 8))
})
t.Run("should not panic", func(t *testing.T) {
for player := 0; player < 8; player++ {
for _, button := range allButtons {
btnPlayer(button, player)
}
}
})
}
func TestBtnp(t *testing.T) {
testBtn(t, pi.Btnp)
}
func TestBtnpPlayer(t *testing.T) {
testBtnPlayer(t, pi.BtnpPlayer)
}
func TestBtnBits(t *testing.T) {
t.Run("should not panic", func(t *testing.T) {
pi.BtnBits()
})
}
func TestBtnpBits(t *testing.T) {
t.Run("should not panic", func(t *testing.T) {
pi.BtnpBits()
})
}