-
Notifications
You must be signed in to change notification settings - Fork 1.1k
added tests #1024
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?
added tests #1024
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * @param {number} value | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,52 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
|
|
||
| const splitInteger = require('./splitInteger'); | ||
| const splitInteger = require("./splitInteger"); | ||
|
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. Consider adding a small helper function in this test file (e.g., |
||
|
|
||
| function assertSplitProperties(value, numberOfParts) { | ||
| const result = splitInteger(value, numberOfParts); | ||
|
|
||
| expect(result).toHaveLength(numberOfParts); | ||
|
|
||
| expect(result.reduce((acc, val) => acc + val, 0)).toBe(value); | ||
|
|
||
| result.forEach((el) => expect(Number.isInteger(el)).toBe(true)); | ||
|
|
||
| for (let i = 0; i < result.length - 1; i++) { | ||
| expect(result[i + 1]).toBeGreaterThanOrEqual(result[i]); | ||
| } | ||
|
|
||
| const min = Math.min(...result); | ||
| const max = Math.max(...result); | ||
|
|
||
| expect(max - min).toBeLessThanOrEqual(1); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| test(`should split a number into equal parts | ||
| if a value is divisible by a numberOfParts`, () => { | ||
|
|
||
| expect(assertSplitProperties(6, 2)).toEqual([3, 3]); | ||
| }); | ||
|
|
||
| test(`should return a part equals to a value | ||
| when splitting into 1 part`, () => { | ||
| expect(assertSplitProperties(8, 1)).toEqual([8]); | ||
| }); | ||
|
|
||
| test("should sort parts ascending if they are not equal", () => { | ||
| const result = assertSplitProperties(17, 4); | ||
|
|
||
| expect(result).toEqual([4, 4, 4, 5]); | ||
| }); | ||
|
|
||
| test('should sort parts ascending if they are not equal', () => { | ||
| test("should add zeros if value < numberOfParts", () => { | ||
| const result = assertSplitProperties(5, 6); | ||
|
|
||
| expect(result).toContain(0); | ||
| }); | ||
|
|
||
| test('should add zeros if value < numberOfParts', () => { | ||
| test("should handle example splitInteger(32, 6)", () => { | ||
| const result = assertSplitProperties(32, 6); | ||
|
|
||
| expect(result).toEqual([5, 5, 5, 5, 6, 6]); | ||
| }); | ||
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 suite is missing the required example cases
splitInteger(17, 4)andsplitInteger(32, 6)which the task description expects to be tested. Add tests that assert those exact behaviors (or the required properties for those inputs). The description lists the examples that must be satisfied:splitInteger(8,1),splitInteger(6,2),splitInteger(17,4), andsplitInteger(32,6).