Skip to content

Commit

Permalink
update contract
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Aug 7, 2023
1 parent 457eaa2 commit 972eaf2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func BenchmarkPacker(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, _ = packer.Pack(boxes, items)
_ = packer.Pack(boxes, items)
}
}
2 changes: 1 addition & 1 deletion internal/visualize3d/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
boxpacker3.NewItem(uuid.New().String(), 35, 100, 100, 2690),
}

packResult, _ := packer.Pack(boxes, items)
packResult := packer.Pack(boxes, items)

for _, box := range packResult.Boxes {
if len(box.GetItems()) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewPacker() *Packer {
return &Packer{}
}

func (p *Packer) Pack(inputBoxes []*Box, inputItems []*Item) (*Result, error) {
func (p *Packer) Pack(inputBoxes []*Box, inputItems []*Item) *Result {
boxes := boxSlice(copySlicePtr(inputBoxes))
items := itemSlice(copySlicePtr(inputItems))

Expand All @@ -39,7 +39,7 @@ func (p *Packer) Pack(inputBoxes []*Box, inputItems []*Item) (*Result, error) {
result.UnfitItems = append(result.UnfitItems, items...)
}

return result, nil
return result
}

func (p *Packer) preferredSort(boxes boxSlice, items itemSlice) boxSlice {
Expand Down
24 changes: 8 additions & 16 deletions packer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (s *PackerSuit) TestMinBox() {
5,
384)

packResult, err := packer.Pack(boxes, []*boxpacker3.Item{item})
require.NoError(t, err)
packResult := packer.Pack(boxes, []*boxpacker3.Item{item})
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down Expand Up @@ -122,8 +121,7 @@ func (s *PackerSuit) TestRotate() {
boxpacker3.NewItem(uuid.New().String(), 100, 380, 250, 2690),
}

packResult, err := packer.Pack(boxes, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down Expand Up @@ -152,8 +150,7 @@ func (s *PackerSuit) TestStd() {
boxpacker3.NewItem(uuid.New().String(), 100, 380, 250, 2690),
}

packResult, err := packer.Pack(boxes, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down Expand Up @@ -188,8 +185,7 @@ func (s *PackerSuit) TestBoxTypeF() {
boxpacker3.NewItem(uuid.New().String(), 35, 100, 100, 2500),
}

packResult, err := packer.Pack(boxes, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down Expand Up @@ -224,8 +220,7 @@ func (s *PackerSuit) TestBoxTypeF_Weight() {
boxpacker3.NewItem(uuid.New().String(), 35, 100, 100, 2690), // maxWeight > 20_000
}

packResult, err := packer.Pack(boxes, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down Expand Up @@ -270,8 +265,7 @@ func (s *PackerSuit) TestPacker_AllBoxes() {
boxpacker3.NewItem(uuid.New().String(), 1000, 500, 500, 20000),
}

packResult, err := packer.Pack(reverse, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

require.Len(t, packResult.UnfitItems, 0)
Expand All @@ -295,8 +289,7 @@ func (s *PackerSuit) TestPacker_UnfitItems() {
boxpacker3.NewItem(uuid.New().String(), 3000, 3000, 3000, 20001),
}

packResult, err := packer.Pack(boxes, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

require.Len(t, packResult.UnfitItems, 4)
Expand Down Expand Up @@ -341,8 +334,7 @@ func (s *PackerSuit) TestPacker_MinAndStd() {
boxpacker3.NewItem(uuid.New().String(), 3000, 3000, 3000, 20000), // 14. NotStd6
}

packResult, err := packer.Pack(reverse, items)
require.NoError(t, err)
packResult := packer.Pack(boxes, items)
require.NotNil(t, packResult)

checks := map[string]int{
Expand Down

0 comments on commit 972eaf2

Please sign in to comment.