Skip to content

js_split_integer#1023

Open
Alex-redman wants to merge 1 commit into
mate-academy:mainfrom
Alex-redman:develop
Open

js_split_integer#1023
Alex-redman wants to merge 1 commit into
mate-academy:mainfrom
Alex-redman:develop

Conversation

@Alex-redman
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Approved because the implementation appears correct and the existing tests cover the core example behaviors and edge case. However, the tests are missing explicit assertions for the general properties required by the checklist (array type, correct length, integer elements, sum preservation, sorted order, and max−min ≤ 1). Strength: you correctly test key examples like splitInteger(6,2), (8,1), (17,4), and an edge case where value < numberOfParts. To strengthen the suite, please add property-based checks alongside the example assertions in src/splitInteger.test.js (around the existing result expectations) and consider including the missing example splitInteger(32, 6) → [5, 5, 5, 5, 6, 6]. Suggested assertions to add near those lines: Array.isArray(result), result.length === numberOfParts, result.every(Number.isInteger), sum equals value, sorted ascending, and Math.max(...result) - Math.min(...result) ≤ 1. Nice work overall—these additions will make your tests document the required behavior more robustly.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/splitInteger.test.js

test(`should split a number into equal parts
if a value is divisible by a numberOfParts`, () => {
const result = splitInteger(6, 2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test computes result for splitInteger(6, 2) — good. Consider adding explicit property assertions here (instead of relying only on exact array equality) to verify the checklist items: array type, correct length, integer elements, sum equals input, sortedness, and max-min <= 1. For example:

expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(2);
expect(result.every(Number.isInteger)).toBe(true);
expect(result.reduce((a,b)=>a+b,0)).toBe(6);
expect(Math.max(...result) - Math.min(...result)).toBeLessThanOrEqual(1);
expect(result).toEqual([...result].sort((a,b)=>a-b));

Adding these checks will ensure the test verifies the general properties from the task, not just one concrete output. (See checklist items 3.1–3.5.)

Comment thread src/splitInteger.test.js
if a value is divisible by a numberOfParts`, () => {
const result = splitInteger(6, 2);

expect(result).toEqual([3, 3]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expect(result).toEqual([3, 3]) is fine for the specific example, but it would be more robust to also assert the general properties (length, sum, integer-ness, sorted, max-min <= 1). That way tests document the required behavior rather than only one canonical output.

Comment thread src/splitInteger.test.js
test('should sort parts ascending if they are not equal', () => {
const result = splitInteger(17, 4);

expect(result).toEqual([4, 4, 4, 5]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you check a non-equal-parts example here. Also consider adding the additional example from the description splitInteger(32, 6) === [5, 5, 5, 5, 6, 6] to mirror the specification. More importantly, add a general-property assertion (array type, length, integers, sum, sorted, max-min <=1) either here or in a separate helper test so the checklist items are explicitly verified.

Comment thread src/splitInteger.test.js
});

test('should add zeros if value < numberOfParts', () => {
const result = splitInteger(3, 5);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edge-case test for value < numberOfParts is present and asserts the expected array. Please also assert result.length === 5, that all elements are integers, the sum equals the original value (3), that the array is sorted, and Math.max(...result) - Math.min(...result) <= 1. These explicit checks ensure the function adheres to the task constraints for such edge cases (checklist items 3.1, 3.2, 3.3, 3.4, 3.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants