-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_sheet_test.go
57 lines (48 loc) · 1.34 KB
/
sprite_sheet_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
// (c) 2022 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package pi_test
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/elgopher/pi"
)
func TestUseEmptySpriteSheet(t *testing.T) {
invalidSpriteSheetSizes := [...]int{
0, 1, 7, 9,
}
t.Run("should panic if SpriteSheetWidth is not multiple of 8", func(t *testing.T) {
for _, width := range invalidSpriteSheetSizes {
t.Run(strconv.Itoa(width), func(t *testing.T) {
pi.Reset()
assert.Panics(t, func() {
pi.UseEmptySpriteSheet(width, pi.SprSheet().Height())
})
})
}
})
t.Run("should panic if SpriteSheetHeight is not multiple of 8", func(t *testing.T) {
for _, height := range invalidSpriteSheetSizes {
t.Run(strconv.Itoa(height), func(t *testing.T) {
pi.Reset()
assert.Panics(t, func() {
pi.UseEmptySpriteSheet(pi.SprSheet().Width(), height)
})
})
}
})
t.Run("should use custom size sprite sheet", func(t *testing.T) {
pi.Reset()
// when
pi.UseEmptySpriteSheet(16, 8)
// then
expectedSpriteSheetData := make([]byte, 16*8)
assert.Equal(t, expectedSpriteSheetData, pi.SprSheet().Pix())
})
t.Run("should panic when total number of pixels is higher than 65536", func(t *testing.T) {
pi.Reset()
assert.Panics(t, func() {
pi.UseEmptySpriteSheet(256, 264)
})
})
}