We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47836c2 commit b73ef69Copy full SHA for b73ef69
src/algorithms/knapsack-fractional.spec.js
@@ -42,4 +42,26 @@ describe('solveFractionalKnapsack', () => {
42
expect(knapsack.value).toBeCloseTo(6 + 7 + 4);
43
expect(knapsack.items.length).toEqual(3);
44
});
45
+
46
+ it('should take none if max is 0', () => {
47
+ const maxWeight = 0;
48
+ const items = [
49
+ { value: 1, weight: 1 }, // 1/1 = 1
50
+ ];
51
+ const knapsack = solveFractionalKnapsack(items, maxWeight);
52
+ expect(knapsack.items.length).toEqual(0);
53
+ expect(knapsack.weight).toBeCloseTo(0);
54
+ expect(knapsack.value).toBeCloseTo(0);
55
+ });
56
57
+ it('should take all if capacity allows it', () => {
58
+ const maxWeight = 10;
59
60
61
62
63
+ expect(knapsack.items.length).toEqual(1);
64
+ expect(knapsack.weight).toBeCloseTo(1);
65
+ expect(knapsack.value).toBeCloseTo(1);
66
67
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments