Skip to content

London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | implement and rewrite tests coursework#1261

Open
djebsoft wants to merge 18 commits intoCodeYourFuture:mainfrom
djebsoft:sprint-3/implement-and-rewrite-tests-coursework
Open

London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | implement and rewrite tests coursework#1261
djebsoft wants to merge 18 commits intoCodeYourFuture:mainfrom
djebsoft:sprint-3/implement-and-rewrite-tests-coursework

Conversation

@djebsoft
Copy link

Learners, PR Template

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

Changelist

implement and tests functions

Questions

@djebsoft djebsoft added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 13, 2026
Comment on lines +32 to +36
if (card[0] === "A") return 11;
if (["J", "Q", "K"].includes(card[0])) return 10;
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(card[0]))
return card[0]; // the parseint() or Number() can be used to convert the string to a number
throw new Error("invalid rank");
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your function return the value you expected from each of the following function calls?

getCardValue("+2♠");
getCardValue("2.0♠");
getCardValue("11♠");
getCardValue("2      ♠");
getCardValue("XYZ2♠");

Copy link
Author

Choose a reason for hiding this comment

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

i tested all these sases and yes it does
the return is either invalid suit or invalid rank
but I made some changes in case as follows:
I declared the suit and rank parts as different variables to get the valid results only when the input maches exactly the condition

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 15, 2026
Comment on lines +49 to +61
test(`should return false for improper fraction`, () => {
expect(isProperFraction(2, -1)).toEqual(false);
});

// case: both values of the numerator and denominator are negative and the absolute value of the numerator is less than the absolute value of the denominator (proper fraction)
test(`should return true for proper fraction`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});

// case: both values of the numerator and denominator are negative and the absolute value of the numerator is greater than the absolute value of the denominator (improper fraction)
test(`should return false for improper fraction`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

When multiple tests share the same description, a failure can make it harder and slower to identify which specific test failed.

You could consider combine the tests with the same description into the same group.

Copy link
Author

Choose a reason for hiding this comment

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

the same description, do you mean the same return value or the same status of the denominator and numerator ?
I tryed grouping them based on the return value

Copy link
Contributor

@cjyuan cjyuan Mar 16, 2026

Choose a reason for hiding this comment

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

I mean the string value passed to test() as the first argument. When a test fails, that's the string Jest output.

Comment on lines +17 to +27
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("3♥")).toEqual(3);
expect(getCardValue("4♦")).toEqual(4);
expect(getCardValue("5♣")).toEqual(5);
expect(getCardValue("6♥")).toEqual(6);
expect(getCardValue("7♠")).toEqual(7);
expect(getCardValue("8♦")).toEqual(8);
expect(getCardValue("9♠")).toEqual(9);
expect(getCardValue("10♣")).toEqual(10);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think your function can pass this test yet.

Copy link
Author

Choose a reason for hiding this comment

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

I changed the returned outcome to a number in the function
return Number(cardRank)

…e card, which can have a value of either 1 or 11 depending on the context of the hand. This allows the function to correctly calculate the value of the hand in blackjack, where the ace can be counted as either 1 or 11 to maximize the player's chances of winning.
@djebsoft djebsoft added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 16, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Changes look good. Well done.

Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Changes look good. Well done.


// case: both values are positive and the value of the numerater is less than the value of the denominater (proper fraction)
// Special case: numerator is zero (proper fraction)
test(`should return true for proper fraction`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The grouping is good.

Could also consider including the condition abs(numerator) < abs(denominator) in the description so that one does not need to lookup the definition of proper fraction.

@cjyuan cjyuan 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 Mar 16, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants