Skip to content

splitInteger tests#1040

Open
Yaroslav65 wants to merge 3 commits intomate-academy:mainfrom
Yaroslav65:develop
Open

splitInteger tests#1040
Yaroslav65 wants to merge 3 commits intomate-academy:mainfrom
Yaroslav65:develop

Conversation

@Yaroslav65
Copy link

No description provided.

Copy link

@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

Great work setting up the test file and covering a variety of scenarios for the splitInteger function. However, this requires changes because the current assertions are not specific enough to guarantee the function is working correctly. The tests check properties like array length but fail to verify that the sum of the resulting parts equals the original input value, which is a critical requirement.

For example, in your first test for splitInteger(8, 2), an incorrect result like [3, 3] would pass the checks, but its sum is 6, not 8. A more robust approach is to assert the exact expected output:

expect(result).toStrictEqual([4, 4]);

This single check validates the length, content, order, and sum all at once. Please update your tests to use this stricter form of assertion.


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 9 to 13
const min = Math.min(...result);
const max = Math.max(...result);

expect(max - min).toBeLessThanOrEqual(1);
expect(result).toHaveLength(2);

Choose a reason for hiding this comment

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

These assertions check some of the requirements, but they aren't strict enough. For example, an incorrect result like [3, 3] would pass these checks, but the sum of its parts is 6, not 8. A more robust approach is to assert the exact expected output:

expect(result).toStrictEqual([4, 4]);

This single check validates the length, content, order, and sum all at once.

Comment on lines 28 to 33
const min = Math.min(...result);
const max = Math.max(...result);

expect(max - min).toBeLessThanOrEqual(1);
expect(result).toStrictEqual(sorted);
expect(result).toHaveLength(3);

Choose a reason for hiding this comment

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

Similar to the first test, these assertions don't verify that the sum of the parts equals the original value. An array like [1, 1, 2] would pass these checks, but its sum is 4, not 5. It's great that you're checking if the array is sorted, but you should also ensure the total value is correct. The most direct way is to check against the expected array:

expect(result).toStrictEqual([1, 2, 2]);

Copy link

@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

You've done a great job updating most of your tests to use toStrictEqual! This makes your test suite much more robust. However, I'm requesting one small change before this can be approved.

The final test case in src/splitInteger.test.js for splitInteger(6, 8) still uses multiple assertions instead of a single strict one. This approach doesn't fully verify that the array is sorted or that the values are distributed correctly.

Please update this last test to use a single toStrictEqual assertion, just like you did for the others. The expected output should be [0, 0, 1, 1, 1, 1, 1, 1].

Once that's fixed, this will be ready to go!


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 51 to 53
expect(result).toHaveLength(8);
expect(countZeros(result)).toBe(2);
expect(result.reduce((a, b) => a + b, 0)).toBe(6);

Choose a reason for hiding this comment

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

It's great that you've updated the other tests to use toStrictEqual. This last test case should also be updated to use a single, strict assertion. This ensures you're checking all the requirements at once: the exact content, the length, the sum, and the ascending order of the elements.

Copy link

@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

I'm approving this submission to help you keep moving forward, but please review the feedback below for your next task. You've done a great job using toStrictEqual to make your tests more robust, which was a key piece of feedback from last time!

There are two main areas to focus on for improvement:

  1. Missing Test Cases: Your test suite is missing a few required examples from the task description, specifically for splitInteger(6, 2), splitInteger(17, 4), and splitInteger(32, 6). Be sure to include all required tests.
  2. Redundant Assertions: In several tests, you have extra checks that are already covered by toStrictEqual. For example, when you assert toStrictEqual([4, 4]), you don't need separate checks for the array's sum or the difference between its values, because the main assertion already guarantees this. Simplifying your tests to a single, powerful assertion makes them cleaner and more focused.

Excellent progress! Keep these points in mind, and you'll be writing even better tests in no time.


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

Footnotes

  1. Rate AI review example

Comment on lines +9 to +12
const min = Math.min(...result);
const max = Math.max(...result);

expect(max - min).toBeLessThanOrEqual(1);

Choose a reason for hiding this comment

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

These calculations and the assertion on line 12 are redundant. The toStrictEqual([4, 4]) on line 13 is a comprehensive check that already guarantees the difference between the max and min values is 0, which satisfies the requirement.

when splitting into 1 part`, () => {
const result = splitInteger(6, 1);

expect(result[0]).toBe(6);

Choose a reason for hiding this comment

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

This assertion is redundant because toStrictEqual([6]) on the next line already verifies that the first (and only) element is 6.

Comment on lines +26 to +32
const sorted = [...result].sort((a, b) => a - b);

const min = Math.min(...result);
const max = Math.max(...result);

expect(max - min).toBeLessThanOrEqual(1);
expect(result).toStrictEqual(sorted);

Choose a reason for hiding this comment

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

These checks are helpful for understanding the requirements, but they are redundant. The toStrictEqual([1, 2, 2]) assertion on line 33 already confirms that the array is sorted and that the difference between the max and min values is 1.

Comment on lines +39 to +53
function countZeros(arr) {
let count = 0;

for (const a of arr) {
if (a === 0) {
count++;
}
}

return count;
}

expect(result).toStrictEqual([0, 0, 1, 1, 1, 1, 1, 1]);
expect(countZeros(result)).toBe(2);
expect(result.reduce((a, b) => a + b, 0)).toBe(6);

Choose a reason for hiding this comment

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

The toStrictEqual assertion on line 51 is a great addition! It's a comprehensive check that makes the assertions on lines 52 and 53 unnecessary. A single, powerful assertion is all you need here, which fully addresses the feedback from the previous review. The countZeros function also becomes unnecessary and can be removed.

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