Skip to content

Conversation

@AdnaanA
Copy link

@AdnaanA AdnaanA commented Sep 26, 2025

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

completed the coursework/sprint-3 implement-and-rewrite by answering the questions in the tasks and implementing test-cases and making sure all test-cases have passed.

@AdnaanA AdnaanA added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module labels Sep 26, 2025
…jest/2-is-proper-fraction.test.js

	modified:   Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js
	modified:   Sprint-3/2-practice-tdd/count.test.js
@illicitonion illicitonion added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 1, 2025
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

This is generally looking good, but I left a few things to look at

} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
return Number(rank);
} else {
throw new Error("Invalid card rank");
Copy link
Member

Choose a reason for hiding this comment

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

It can be useful to include what the problematic data was in an error message, so that someone knows what they should be debugging - can you give that a go?

Copy link
Author

Choose a reason for hiding this comment

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

Yes you are correct it would be helpful/useful to include the problematic data in an error message and we can achieve this by doing.

throw new Error('Invalid card rank: "$(rank)"');

Comment on lines +16 to +18
} else if (["K", "Q", "J", "10"].includes(rank)) {
return 10;
} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
Copy link
Member

Choose a reason for hiding this comment

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

You could have handled "10" in either the K/Q/J case, or the 2-9 case - which do you prefer? What advantages/disadvantages do you think each has?

Copy link
Author

Choose a reason for hiding this comment

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

hello,

Thank you for the feedback, I prefer to handle the "10" in the K/Q/J case. for clarity and explicitness, and to maintain semantical grouping since "10" has the same card value as the face cards. a disadvantage could be mixing string handling logic "K/Q/J" with numeric checking logic "10".

We can also handle "10" in the 2-9 case and the pros for this would be logical consistency the numeric branch handles anything numeric between 2-10. and its easier to extend if we ever want to adjust the ranges to include 1 or 11 or validate different ranges we just change the numeric branch. Disadvantages risk of mis-parsing since !isNaN(rank) is loose we might accidently accept strings like "10abc". Edge-case handling we need to make sure to handle trimming, ect. in case someone passes weird strings like "010" and " 10 ".

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks for sharing your thoughts!

Personally I prefer 10 to be included in the number case, because it leads to simpler code. In the numeric case, we already need an upper bound, so the difference between Number(rank) <= 9 and Number(rank) <= 10 is really small, whereas adding a whole extra element to the array we're checking is adding an extra piece: ["K", "Q", "J", "10"] vs ["K", "Q", "J"].

But you're right that there's not one obviously better answer - there are advantages and disadvantages to each :)

expect(getCardValue("A♥")).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should return null for invalid cards", () => {
Copy link
Member

Choose a reason for hiding this comment

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

This test looks like it's expecting something different from your previous test - before it was checking it throws, here it's checking for null. Does the same code pass both tests? Should the tests look more similar?

Copy link
Author

Choose a reason for hiding this comment

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

I have modified the case 5: test to check it throws error rather than checking for null. I have also run a test with pass.

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 1, 2025
@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 2, 2025
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Looks good! Just one thing to fix up and this is done!

console.assert(false, "Expected an error to be thrown for invalid card rank");
} catch (e) {
console.assert(
e.message === 'Invalid card rank: "${rank}"',
Copy link
Member

Choose a reason for hiding this comment

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

There's a tension in testing between calculating expected values in tests (to avoid duplication), or hard-coding expected values (to make it really obvious that the test is correct).

Can you change this test so that it actually includes "1" in the expected error message:

Suggested change
e.message === 'Invalid card rank: "${rank}"',
e.message === 'Invalid card rank: "1"',

I think you'll find that the test is actually failing, so we should fix the code :)

Copy link
Author

Choose a reason for hiding this comment

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

Thank for the feedback and I have now included "1" in the expected error message. I have run the test with a pass.

thank you for the suggested change.

Copy link
Member

Choose a reason for hiding this comment

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

I just ran the test and it failed...

% node Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Assertion failed: Expected error message to be "Invalid card rank" but got "Invalid card rank: "${rank}""

Can you check again?

(Also, your Jest tests wouldn't catch this same bug, can you fix them up so they do as well?)

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for picking on that and being patient with me. test was not failing on my side because Jest’s .toThrow("Invalid card rank") only checks that the error message contains that substring, not that it matches exactly. now I have updated the code and it passes as it should.

Comment on lines +16 to +18
} else if (["K", "Q", "J", "10"].includes(rank)) {
return 10;
} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks for sharing your thoughts!

Personally I prefer 10 to be included in the number case, because it leads to simpler code. In the numeric case, we already need an upper bound, so the difference between Number(rank) <= 9 and Number(rank) <= 10 is really small, whereas adding a whole extra element to the array we're checking is adding an extra piece: ["K", "Q", "J", "10"] vs ["K", "Q", "J"].

But you're right that there's not one obviously better answer - there are advantages and disadvantages to each :)

@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 2, 2025
@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 2, 2025
@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 3, 2025
@AdnaanA AdnaanA added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 3, 2025
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@illicitonion illicitonion added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants