mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
packing: Add IsEmpty tests
This commit is contained in:
parent
6c9d9dbaff
commit
9555e83589
@ -72,6 +72,37 @@ func TestPage(t *testing.T) {
|
|||||||
{0, 0, 1024, 1024},
|
{0, 0, 1024, 1024},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "alloc and free and empty",
|
||||||
|
In: []Op{
|
||||||
|
{31, 41, -1},
|
||||||
|
{59, 26, -1},
|
||||||
|
{53, 58, -1},
|
||||||
|
{97, 93, -1},
|
||||||
|
{28, 84, -1},
|
||||||
|
{62, 64, -1},
|
||||||
|
{0, 0, 0},
|
||||||
|
{0, 0, 1},
|
||||||
|
{0, 0, 2},
|
||||||
|
{0, 0, 3},
|
||||||
|
{0, 0, 4},
|
||||||
|
{0, 0, 5},
|
||||||
|
},
|
||||||
|
Out: []*Rect{
|
||||||
|
{0, 0, 31, 41},
|
||||||
|
{31, 0, 59, 26},
|
||||||
|
{31, 26, 53, 58},
|
||||||
|
{31, 84, 97, 93},
|
||||||
|
{0, 41, 28, 84},
|
||||||
|
{31, 177, 62, 64},
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "random Alloc",
|
Name: "random Alloc",
|
||||||
In: []Op{
|
In: []Op{
|
||||||
@ -182,13 +213,23 @@ func TestPage(t *testing.T) {
|
|||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
p := NewPage(1024)
|
p := NewPage(1024)
|
||||||
nodes := []*Node{}
|
nodes := []*Node{}
|
||||||
for _, in := range c.In {
|
nnodes := 0
|
||||||
|
for i, in := range c.In {
|
||||||
if in.FreeNodeID == -1 {
|
if in.FreeNodeID == -1 {
|
||||||
n := p.Alloc(in.Width, in.Height)
|
n := p.Alloc(in.Width, in.Height)
|
||||||
nodes = append(nodes, n)
|
nodes = append(nodes, n)
|
||||||
|
nnodes++
|
||||||
} else {
|
} else {
|
||||||
p.Free(nodes[in.FreeNodeID])
|
p.Free(nodes[in.FreeNodeID])
|
||||||
nodes = append(nodes, nil)
|
nodes = append(nodes, nil)
|
||||||
|
nnodes--
|
||||||
|
}
|
||||||
|
if nnodes < 0 {
|
||||||
|
panic("not reached")
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.IsEmpty() != (nnodes == 0) {
|
||||||
|
t.Errorf("%s: nodes[%d]: page.IsEmpty(): got: %v, want: %v", c.Name, i, p.IsEmpty(), (nnodes == 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, out := range c.Out {
|
for i, out := range c.Out {
|
||||||
|
Loading…
Reference in New Issue
Block a user