-
Notifications
You must be signed in to change notification settings - Fork 1.1k
all tests passed #1014
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?
all tests passed #1014
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2,20 +2,44 @@ | |
|
|
||
| const splitInteger = require('./splitInteger'); | ||
|
|
||
| function assertProperties(value, numberOfParts) { | ||
| const result = splitInteger(value, numberOfParts); | ||
|
|
||
| expect(result.every(Number.isInteger)).toBe(true); | ||
|
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.
|
||
|
|
||
| expect(result).toHaveLength(numberOfParts); | ||
|
|
||
| for (let i = 0; i < result.length - 1; i++) { | ||
| expect(result[i]).toBeLessThanOrEqual(result[i + 1]); | ||
| } | ||
| expect(Math.max(...result) - Math.min(...result)).toBeLessThanOrEqual(1); | ||
| expect(result.reduce((a, b) => a + b, 0)).toBe(value); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| test(`should split a number into equal parts | ||
| if a value is divisible by a numberOfParts`, () => { | ||
| const result = assertProperties(6, 2); | ||
|
|
||
| expect(result).toEqual([3, 3]); | ||
| }); | ||
|
|
||
| test(`should return a part equals to a value | ||
| when splitting into 1 part`, () => { | ||
| const result = assertProperties(8, 1); | ||
|
|
||
| expect(result).toEqual([8]); | ||
| }); | ||
|
|
||
| test('should sort parts ascending if they are not equal', () => { | ||
| const result = assertProperties(17, 4); | ||
|
|
||
| expect(result).toEqual([4, 4, 4, 5]); | ||
| }); | ||
|
|
||
| test('should add zeros if value < numberOfParts', () => { | ||
| const result = assertProperties(2, 5); | ||
|
|
||
| expect(result).toEqual([0, 0, 0, 1, 1]); | ||
|
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. Two tests are still missing from the checklist:
Add these tests (after the existing ones) so all provided examples and required edge cases are covered. |
||
| }); | ||
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.
Add an explicit check that the result is an array before using array methods. The task requires the function to return an array; currently you call
result.every(...)which will throw ifresultis not an array. Addexpect(Array.isArray(result)).toBe(true);before theeveryassertion.