-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacker_test.go
61 lines (56 loc) · 1.11 KB
/
packer_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
package pckr_test
import (
"testing"
"github.com/yohamta/pckr"
)
func TestSimplePackerAlgo(t *testing.T) {
type result struct {
isPressed bool
}
R := make([]*pckr.Rectangle, 0)
// random 50 rectangles with different size between 16x16 and 256x256
for _, v := range [][]int{
{300, 600},
{700, 400},
{700, 600},
{300, 400},
} {
r := pckr.Rect(v[0], v[1])
R = append(R, &r)
}
var tests = []struct {
name string
a []*pckr.Rectangle
b int
want bool
}{
{"pack rects w/o overlaps", R, 1000, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := _TestSimpleAlgo(tt.a, tt.b)
if got != tt.want {
t.Errorf("TestPaking(%s): got %v; want %v", tt.name, got, tt.want)
}
})
}
}
func _TestSimpleAlgo(R []*pckr.Rectangle, size int) bool {
algo := pckr.SimpleAlgo{}
algo.Pack(R, size, size)
arr := make([][]bool, size)
for i := range arr {
arr[i] = make([]bool, size)
}
for _, r := range R {
for i := r.X; i < r.X+r.W; i++ {
for j := r.Y; j < r.Y+r.H; j++ {
if arr[i][j] {
return false
}
arr[i][j] = true
}
}
}
return true
}