Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Aug 10, 2023
1 parent 7a551c6 commit 78d3aa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ func (p *Packer) preferredSort(boxes boxSlice, items itemSlice) boxSlice {
func (p *Packer) packToBox(b *Box, items []*Item) []*Item {
var fitted bool

unpacked := make([]*Item, 0, len(items))
cntItems := len(items)
unpacked := make([]*Item, 0, cntItems)
pv := Pivot{}

if b.items == nil && b.PutItem(items[0], pv) {
if b.items == nil && cntItems > 0 && b.PutItem(items[0], pv) {
items = items[1:]
}

Expand Down
26 changes: 26 additions & 0 deletions packer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ func TestBoxPackerSuite(t *testing.T) {
suite.Run(t, new(PackerSuit))
}

func (s *PackerSuit) TestEmptyBoxes() {
t := s.T()
t.Parallel()

packer := boxpacker3.NewPacker()

packResult := packer.Pack(nil, nil)
require.NotNil(t, packResult)
require.Len(t, packResult.Boxes, 0)
require.Len(t, packResult.UnfitItems, 0)
}

func (s *PackerSuit) TestEmptyItems() {
t := s.T()
t.Parallel()

packer := boxpacker3.NewPacker()

boxes := NewDefaultBoxList()

packResult := packer.Pack(boxes, nil)
require.NotNil(t, packResult)
require.Len(t, packResult.Boxes, len(boxes))
require.Len(t, packResult.UnfitItems, 0)
}

func (s *PackerSuit) TestMinBox() {
t := s.T()
t.Parallel()
Expand Down

0 comments on commit 78d3aa2

Please sign in to comment.