Skip to content

London | May-2025 | Fatima_Zohra_Belkedari | Module Structuring and Testing Data | Sprint. 3 #629

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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

Farah-Stu
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

Comment on lines 6 to 7
const number = Number(rank);
if (number >= 2 && number <= 10) return number;
Copy link
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "00_02".

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

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("00_02♠");

Copy link
Author

Choose a reason for hiding this comment

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

I tried and used chat gpt but I dont't want to copy and paste without understanding. I would appreciate if you could explain to me.

Copy link
Author

Choose a reason for hiding this comment

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

I run the code and it did't return what was expected with the functions above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not update the code to throw error with the argument is one of these?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("00_02♠");

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 11 to 22
test("should return 10 for Jack of Diamonds", () => {
expect(getCardValue ("J")).toEqual(10);
});

test("should return 10 for Queen of Clubs", () => {
expect(getCardValue("Q")).toEqual(10);
});

test("should return 10 for King of Spades", () => {
expect(getCardValue("K")).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.

We could combine these tests under the category "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K).

Copy link
Author

Choose a reason for hiding this comment

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

Ok.
test("should return 10 for face cards J,Q,K", () => {
["J" ,"Q" ,"K"] .forEach(rank) => {
expect(getCardValue(rank)).toEqual (10);
});
});

Copy link
Contributor

@cjyuan cjyuan Jul 12, 2025

Choose a reason for hiding this comment

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

The approach you suggested in your previous comment works. Why not update the code 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.

ok, noted.

Comment on lines +2 to +21
const strNum= num.toString();
if(strNum.slice(-2)==="11") {
return strNum + "th";
}
if(strNum.slice(-2)==="12") {
return strNum + "th";
}
if(strNum.slice(-2)==="13") {
return strNum + "th";
}
if(strNum.slice(-1)==="1") {
return strNum + "st";
}
if(strNum.slice(-1)==="2") {
return strNum + "nd";
}
if(strNum.slice(-1)==="3") {
return strNum + "rd";
}

Copy link
Contributor

Choose a reason for hiding this comment

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

  • If num is an integer, we could also use % to extract the last one or two digits from its value.

  • What should the function return when num is 10, 15, or 124?

Copy link
Author

Choose a reason for hiding this comment

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

If we use the number%10 we will get the last digit. In this case :
10 % 10 = 0
15 % 10 = 5
124 % 10 = 4

Copy link
Contributor

Choose a reason for hiding this comment

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

What does your function return when num is 10, 15, or 124?

Copy link
Author

Choose a reason for hiding this comment

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

number will return the remainder

Copy link
Author

Choose a reason for hiding this comment

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

10 % 10 = 0
15 % 10 = 5
124 % 10 = 4

Comment on lines 15 to 17
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories. Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.

For example, we can prepare a test for numbers 2, 22, 132, etc. as

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
    expect( getOrdinalNumber(2) ).toEqual("2nd");
    expect( getOrdinalNumber(22) ).toEqual("22nd");
    expect( getOrdinalNumber(132) ).toEqual("132nd");
});

Can you update the tests in this script so that they can cover all valid integers?

Copy link
Author

Choose a reason for hiding this comment

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

test("append 'st' to numbers ending in 1" , () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(121)).toEqual("121st");
});

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
    expect(getOrdinalNumber(2)).toEqual("2nd");
    expect(getOrdinalNumber(22)).toEqual("22nd");
    expect(getOrdinalNumber(132)).toEqual("132nd");
});

test("append 'rd' to numbers ending in 3 , except those ending in 13", () => {
    expect(getOrdinalNumber(23)).toEqual("23rd");
    expect(getOrdinalNumber(13)).toEqual("13th");
    expect(getOrdinalNumber(3)).toEqual("3rd");
});

test("should return '11th' for 11", () => {
    expect(getOrdinalNumber(11)).toEqual("11th");
});     

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 8, 2025
@Farah-Stu Farah-Stu removed the Reviewed Volunteer to add when completing a review label Jul 11, 2025
@Farah-Stu Farah-Stu added the Needs Review Participant to add when requesting review label Jul 11, 2025
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.

Some of the code could still use some improvement.

expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(13)).toEqual("13th");
Copy link
Contributor

Choose a reason for hiding this comment

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

"except those ending in 13".

Numbers ending in 12, and 13 could be placed together with numbers ending in 11 in the same category.

Comment on lines +2 to +21
const strNum= num.toString();
if(strNum.slice(-2)==="11") {
return strNum + "th";
}
if(strNum.slice(-2)==="12") {
return strNum + "th";
}
if(strNum.slice(-2)==="13") {
return strNum + "th";
}
if(strNum.slice(-1)==="1") {
return strNum + "st";
}
if(strNum.slice(-1)==="2") {
return strNum + "nd";
}
if(strNum.slice(-1)==="3") {
return strNum + "rd";
}

Copy link
Contributor

Choose a reason for hiding this comment

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

What does your function return when num is 10, 15, or 124?

Comment on lines 6 to 7
const number = Number(rank);
if (number >= 2 && number <= 10) return number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not update the code to throw error with the argument is one of these?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("00_02♠");

Comment on lines 11 to 22
test("should return 10 for Jack of Diamonds", () => {
expect(getCardValue ("J")).toEqual(10);
});

test("should return 10 for Queen of Clubs", () => {
expect(getCardValue("Q")).toEqual(10);
});

test("should return 10 for King of Spades", () => {
expect(getCardValue("K")).toEqual(10);
});

Copy link
Contributor

@cjyuan cjyuan Jul 12, 2025

Choose a reason for hiding this comment

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

The approach you suggested in your previous comment works. Why not update the code as well?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 12, 2025
@Farah-Stu Farah-Stu added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jul 12, 2025
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.

get-ordinal-number.js and get-ordinal-number.test.js can still use some improvement.

All other changes look good.

Comment on lines +28 to +33

test("should return '11th' for 11 , 12, 13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include this test to the script and then check if your function can pass this test:

    // Replace _______ by the value you expected
    test("should append '__' to number ending in 0, 4-9", () => {
        expect(getOrdinalNumber(124)).toEqual( _______ );
        expect(getOrdinalNumber(10)).toEqual( _______ );
        expect(getOrdinalNumber(99)).toEqual( _______ );   
    }); 

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants