-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rozwiązanie zadania Split Integer #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
8e9a71f
8aa5b28
c965be9
8fbb69e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,16 @@ const splitInteger = require('./splitInteger'); | |
|
|
||
| test(`should split a number into equal parts | ||
| if a value is divisible by a numberOfParts`, () => { | ||
|
|
||
| }); | ||
|
|
||
| test(`should return a part equals to a value | ||
| when splitting into 1 part`, () => { | ||
|
|
||
| expect(splitInteger(17, 4)) | ||
| .toHaveLength(4); | ||
| }); | ||
|
|
||
| test('should sort parts ascending if they are not equal', () => { | ||
|
|
||
| expect(splitInteger(32, 6)) | ||
| .toEqual([5, 5, 5, 5, 6, 6]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion Example additional assertions: const parts = splitInteger(32, 6);
expect(parts).toHaveLength(6);
expect(parts.every(Number.isInteger)).toBe(true);
expect(parts.reduce((a,b)=>a+b,0)).toBe(32);
expect(Math.max(...parts) - Math.min(...parts)).toBeLessThanOrEqual(1);Adding these ensures the test suite verifies all required behaviors, not just this single example match. |
||
| }); | ||
|
|
||
| test('should add zeros if value < numberOfParts', () => { | ||
|
|
||
| expect(splitInteger(17, 0)) | ||
| .toEqual([]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is invalid given the task's input assumptions and the test title. It calls Suggested replacement: const parts = splitInteger(2, 5);
expect(parts).toEqual([0, 0, 0, 1, 1]);
expect(parts).toHaveLength(5);
expect(parts.reduce((a,b)=>a+b,0)).toBe(2);
expect(parts.every(Number.isInteger)).toBe(true);
expect(Math.max(...parts) - Math.min(...parts)).toBeLessThanOrEqual(1);This aligns the test input with the task requirements and the test title. |
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test calls
splitInteger(17, 4)but the test title says "if a value is divisible by a numberOfParts" — 17 is not divisible by 4. Also this test only asserts the returned array length. Per the task requirements you must assert the actual distribution (for (17,4) the expected array is[4,4,4,5]) or use a truly divisible example such assplitInteger(8, 1)orsplitInteger(6, 2). Additionally, each test should check the other required properties: sum equals the input value, all elements are integers, array is sorted non-decreasingly, andmax - min <= 1.Consider changing this assertion to one of the following approaches:
splitInteger(6, 2)and asserttoEqual([3, 3])plus the other properties.This is necessary to satisfy these checklist items: exact example outputs, sum preservation, integer elements, sortedness, and max-min difference requirement.