Skip to content

[Bug]: allocation algorithm is incorrect #776

@mzedeler

Description

@mzedeler

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Running this test:

diff --git a/packages/core/src/utils/__tests__/distribute.test.ts b/packages/core/src/utils/__tests__/distribute.test.ts
index c27c022..fc70529 100644
--- a/packages/core/src/utils/__tests__/distribute.test.ts
+++ b/packages/core/src/utils/__tests__/distribute.test.ts
@@ -29,4 +29,7 @@ describe('distribute', () => {
   it('distributes to empty ratios', () => {
     expect(distributeFn(1003, [])).toEqual([]);
   });
+  it('distributes remainder to the largest ratio', () => {
+    expect(distributeFn(5, [100, 101, 100, 100])).toEqual([1, 2, 1, 1]);
+  });
 });

Should pass, since the largest remaining divisor should receive the remainder, but the test fails because the remainder is just allocated to the first partition.

Expected behavior

expect(distributeFn(5, [100, 101, 100, 100])).toEqual([1, 2, 1, 1]);

Steps to reproduce

  1. apply the patch
  2. run tests
  3. profit

Version

v2.0.0-alpha.9

Environment

node.js 18

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions