Skip to content

Commit

Permalink
Merge pull request #7 from bavix/develop
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
rez1dent3 committed Aug 10, 2023
2 parents 7a551c6 + b044c39 commit 470e805
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.20' ]
go-version: [ '1.20', '1.21' ]
steps:
- uses: actions/checkout@v3
- name: Setup Go
Expand All @@ -23,4 +23,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
version: v1.54.0
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.20' ]
go-version: [ '1.20', '1.21' ]
steps:
- uses: actions/checkout@v3
- name: Setup Go
Expand Down
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 470e805

Please sign in to comment.