Skip to content

Feature/custom test#1058

Open
mlabucki wants to merge 3 commits intomate-academy:mainfrom
mlabucki:feature/custom-test
Open

Feature/custom test#1058
mlabucki wants to merge 3 commits intomate-academy:mainfrom
mlabucki:feature/custom-test

Conversation

@mlabucki
Copy link

helpers in customs

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

Good effort on building out the test suite for splitInteger. However, a few changes are needed to meet all the requirements.

Your test suite is missing two required examples from the task description: splitInteger(17, 4) and splitInteger(32, 6). Please ensure all specified examples are tested directly. Additionally, your custom helper toBeSortedAscending in src/customs.js has a logical error that makes the sorting test unreliable.

To simplify your tests and make them more robust, I recommend replacing the complex custom helpers with Jest's built-in toEqual matcher. A single assertion like expect(splitInteger(6, 2)).toEqual([3, 3]) is clearer and verifies the array's content, length, and order all at once.


✨ 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

src/customs.js Outdated
Comment on lines 3 to 7
function toBeSortedAscending(arr) {
if (hasRemainder(arr) === false) {
return arr.every((val, i) => i === 0 || arr[i - 1] <= val);
}
}

Choose a reason for hiding this comment

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

This toBeSortedAscending function has a couple of significant issues:

  1. The hasRemainder function is called with arr as an argument. However, hasRemainder is defined to accept two numbers, not an array. This is an incorrect use of the function.
  2. If the if condition evaluates to false, this function doesn't return any value, which means it implicitly returns undefined. A function designed for checking a condition should always return true or false.

Consider simplifying this function to only perform the sorting check, as that's its main purpose.

const result = splitInteger(34, 2);
const resultOfCustoms = hasSpilitEqual(result, 34, 2);

expect(resultOfCustoms).toEqual(true);

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're testing this case. However, using a custom helper function makes the test indirect. A simpler and more direct assertion would be expect(splitInteger(6, 2)).toEqual([3, 3]), which directly tests against the example from the requirements.

Copy link
Author

Choose a reason for hiding this comment

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

changed into direct assertion

const result = splitInteger(34, 1);
const resultOfCustoms = hasEqualValueToNumber(result, 34);

expect(resultOfCustoms).toEqual([34]);

Choose a reason for hiding this comment

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

While this assertion works, using the specific example from the requirements (splitInteger(8, 1)) would be better. Also, you can simplify this by removing the custom helper: expect(splitInteger(8, 1)).toEqual([8]).

Copy link
Author

Choose a reason for hiding this comment

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

The helpers from customs will be discussed on the meetong with mentor. Need more info about proper pattern of helpers and siply assertions.

test('should sort parts ascending if they are not equal', () => {
const result = splitInteger(34, 5);

expect(toBeSortedAscending(result)).toBe(true);

Choose a reason for hiding this comment

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

This test correctly checks if the array is sorted, which is one of the requirements. However, it's missing validation for the actual content of the array. The task requires testing specific examples like splitInteger(17, 4). A single assertion expect(splitInteger(17, 4)).toEqual([4, 4, 4, 5]) would verify sorting, correct values, length, and the max-min difference all at once.

test('should add zeros if value < numberOfParts', () => {
const result = howManyZerosInArray(splitInteger(2, 4));

expect(zerosCounts(2, 4)).toBe(result);

Choose a reason for hiding this comment

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

This assertion is not robust enough because it only checks the count of zeros in the result, not the full array content. The actual result for splitInteger(2, 4) is [0, 0, 1, 1]. A better test would be expect(splitInteger(2, 4)).toEqual([0, 0, 1, 1]) to ensure the entire output is correct.

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 am approving this submission as an educational override to help you move forward, but there are a couple of important items to address to fully complete the task.

You've done an excellent job simplifying your tests by using Jest's built-in toEqual matcher, which makes them much cleaner! To finish up, please remember to add the required test case for splitInteger(32, 6). Also, consider updating the last test that uses the hasEqualValueToNumber helper to use toEqual for consistency. This change will allow you to remove the now-unnecessary src/customs.js file.

Keep up the great work!


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

Footnotes

  1. Rate AI review example

return arr.every((val, i) => i === 0 || arr[i - 1] <= val);
}

return true;

Choose a reason for hiding this comment

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

This part of the logic is flawed because it unconditionally returns true when a number is evenly divisible, without actually checking if the array is sorted. It's great that you're no longer using this function, and removing it entirely would be the best solution.

}

function hasEqualValueToNumber(result, number) {
return result[0] === number ? result : false;

Choose a reason for hiding this comment

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

This helper makes the test that uses it more complex than necessary. A direct assertion like expect(result).toEqual([8]) in the test file is much clearer. By updating that test, you can remove this helper and eventually this entire file.

Comment on lines +20 to +23
const result = splitInteger(8, 1);
const resultOfCustoms = hasEqualValueToNumber(result, 8);

expect(resultOfCustoms).toEqual([8]);

Choose a reason for hiding this comment

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

Great job simplifying the other tests to use toEqual! For consistency, you can simplify this test as well. A single line expect(splitInteger(8, 1)).toEqual([8]); would be clearer and achieve the same goal without needing the custom helper.

@mlabucki
Copy link
Author

Question related to customs/helpers

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.

3 participants