-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
(16) New exercise | Permutations #444
base: main
Are you sure you want to change the base?
Conversation
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.
Haven't looked at the the solution yet but one (technically 2) important change needed for the test suite below.
[actual, expected] = outcome( | ||
[1, 2, 3, 4], | ||
[ | ||
[ |
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.
You've got an extra nested array here in the "expected array" that's not needed, but also your outcome
function results in the test passing despite this being an incorrect expected outcome.
That being said, even after fixing this, you don't need an outcome
helper function with an afterEach
that uses .toBe
. You can just use the .toEqual
matcher that's designed exactly for this purpose.
test('Works for array of size two', () => {
expect(permutations([1, 2])).toEqual([
[1, 2],
[2, 1],
]);
});
Having all the tests as per the above format will all pass (and will also fail if you keep the unintended extra nested array in the last test "expected" array.
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.
You've got an extra nested array here in the "expected array" that's not needed, but also your
outcome
function results in the test passing despite this being an incorrect expected outcome.That being said, even after fixing this, you don't need an
outcome
helper function with anafterEach
that uses.toBe
. You can just use the.toEqual
matcher that's designed exactly for this purpose.test('Works for array of size two', () => { expect(permutations([1, 2])).toEqual([ [1, 2], [2, 1], ]); });Having all the tests as per the above format will all pass (and will also fail if you keep the unintended extra nested array in the last test "expected" array.
Yes but the problem with that is, what happens if the learner's solution returns the correct array but in a different order?
You've got an extra nested array here in the "expected array" that's not needed, but also your
outcome
function results in the test passing despite this being an incorrect expected outcome.That being said, even after fixing this, you don't need an
outcome
helper function with anafterEach
that uses.toBe
. You can just use the.toEqual
matcher that's designed exactly for this purpose.test('Works for array of size two', () => { expect(permutations([1, 2])).toEqual([ [1, 2], [2, 1], ]); });Having all the tests as per the above format will all pass (and will also fail if you keep the unintended extra nested array in the last test "expected" array.
OHhhhhhhh wow, I had no idea the following test would pass:
expect([1, 2]).toEqual([2, 1])
I was thinking that the order that the learner's function returns the array in should not matter, and kind of just assumed that toEqual
checks for the order too
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.
Fair point I missed about the toEqual
order. That can be remedied by sorting both sides
test('Works for array of size two', () => {
expect(permutations([1, 2]).sort()).toEqual(
[
[1, 2],
[2, 1],
].sort()
);
});
Note the .sort()
for the expect is after the permutations call, not on the array passed into the permutations call.
Do that, and the order of the matched array won't matter.
Because
It was decided to add new recursion exercises
This PR
Previous
Issue
Related to #27265
Additional Information
Pull Request Requirements
location of change: brief description of change
format, e.g.01_helloWorld: Update test cases
Because
section summarizes the reason for this PRThis PR
section has a bullet point list describing the changes in this PRIssue
section/solutions
folder