-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinpack.spec.ts
More file actions
67 lines (52 loc) · 1.99 KB
/
binpack.spec.ts
File metadata and controls
67 lines (52 loc) · 1.99 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Item, Size, firstFitDecreasing } from "./binpack";
describe("firstFitDecreasing", () => {
it("should pack items into bins correctly", () => {
const capacity = new Size([10]);
const items: Item<string>[] = [
{ obj: "item1", size: new Size([4]) },
{ obj: "item2", size: new Size([3]) },
{ obj: "item3", size: new Size([2]) },
{ obj: "item4", size: new Size([1]) },
];
const bins = firstFitDecreasing(capacity, items);
expect(bins.length).toBe(1);
expect(bins[0].items.length).toBe(4);
});
it("should create new bin if item does not fit in existing bins", () => {
const capacity = new Size([5]);
const items: Item<string>[] = [
{ obj: "item1", size: new Size([4]) },
{ obj: "item2", size: new Size([3]) },
{ obj: "item3", size: new Size([2]) },
{ obj: "item4", size: new Size([1]) },
];
const bins = firstFitDecreasing(capacity, items);
expect(bins.length).toBe(2);
expect(bins[0].items.length).toBe(2);
expect(bins[1].items.length).toBe(2);
});
it("should handle empty items list", () => {
const capacity = new Size([10]);
const items: Item<string>[] = [];
const bins = firstFitDecreasing(capacity, items);
expect(bins.length).toBe(0);
});
it("should handle items larger than capacity", () => {
const capacity = new Size([5]);
const items: Item<string>[] = [{ obj: "item1", size: new Size([6]) }];
const bins = firstFitDecreasing(capacity, items);
expect(bins.length).toBe(0);
});
it("should pack items with multiple dimensions correctly", () => {
const capacity = new Size([10, 10]);
const items: Item<string>[] = [
{ obj: "item1", size: new Size([4, 4]) },
{ obj: "item2", size: new Size([3, 3]) },
{ obj: "item3", size: new Size([2, 2]) },
{ obj: "item4", size: new Size([1, 1]) },
];
const bins = firstFitDecreasing(capacity, items);
expect(bins.length).toBe(1);
expect(bins[0].items.length).toBe(4);
});
});