-
Notifications
You must be signed in to change notification settings - Fork 23
/
box_packer_spec.rb
46 lines (44 loc) · 1.66 KB
/
box_packer_spec.rb
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
require 'box_packer'
require 'pry'
describe '.pack' do
it do
packings = BoxPacker.pack(
container: { dimensions: [15, 20, 13], weight_limit: 50 },
items: [
{ dimensions: [2, 3, 5], weight: 47 },
{ dimensions: [2, 3, 5], weight: 47 },
{ dimensions: [3, 3, 1], weight: 24 },
{ dimensions: [1, 1, 4], weight: 7 },
]
)
expect(packings.length).to eql(3)
expect(packings[0][:weight]).to eql(47.0)
expect(packings[0][:placements].length).to eql(1)
expect(packings[0][:placements][0][:dimensions]).to eql([5, 3, 2])
expect(packings[0][:placements][0][:position]).to eql([0, 0, 0])
expect(packings[1][:weight]).to eql(47.0)
expect(packings[1][:placements].length).to eql(1)
expect(packings[1][:placements][0][:dimensions]).to eql([5, 3, 2])
expect(packings[1][:placements][0][:position]).to eql([0, 0, 0])
expect(packings[2][:weight]).to eql(31.0)
expect(packings[2][:placements].length).to eql(2)
expect(packings[2][:placements][0][:dimensions]).to eql([3, 3, 1])
expect(packings[2][:placements][0][:position]).to eql([0, 0, 0])
expect(packings[2][:placements][1][:dimensions]).to eql([4, 1, 1])
expect(packings[2][:placements][1][:position]).to eql([3, 0, 0])
end
it 'no weight given' do
packings = BoxPacker.pack(
container: { dimensions: [13, 15, 20] },
items: [
{ dimensions: [2, 3, 5] },
{ dimensions: [2, 3, 5] },
{ dimensions: [3, 3, 1] },
{ dimensions: [1, 1, 4] },
]
)
expect(packings.length).to eql(1)
expect(packings[0][:weight]).to eql(0.0)
expect(packings[0][:placements].length).to eql(4)
end
end