Skip to content

Conversation

@PaymanIB
Copy link

  • 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

Tests and functions implemented and tested.

@PaymanIB PaymanIB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 15, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

1 similar comment
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@PaymanIB PaymanIB changed the title London | 25-ITP-Sep | Payman Issa Baiglu |coursework/sprint 3/2-practice-tdd London | 25-ITP-Sep | Payman Issa Baiglu | courseworksprint-3 | 2-practice-tdd Nov 15, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (courseworksprint-3) doesn't match expected format (example: 'Sprint 2', without quotes)

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@PaymanIB PaymanIB changed the title London | 25-ITP-Sep | Payman Issa Baiglu | courseworksprint-3 | 2-practice-tdd London | 25-ITP-Sep | Payman Issa Baiglu | coursework-sprint-3 | 2-practice-tdd Nov 15, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (coursework-sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes)

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@PaymanIB PaymanIB changed the title London | 25-ITP-Sep | Payman Issa Baiglu | coursework-sprint-3 | 2-practice-tdd London | 25-ITP-Sep | Payman Issa Baiglu | sprint-3 | 2-practice-tdd Nov 15, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes)

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@PaymanIB PaymanIB changed the title London | 25-ITP-Sep | Payman Issa Baiglu | sprint-3 | 2-practice-tdd London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 2-practice-tdd Nov 15, 2025
Comment on lines 3 to 4
const v = num % 100;
console.log(v);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • It's best practice to give variables meaningful names. Can you think of a more meaningful name to replace v?
  • Can you keep the code clean by removing all debugging code?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @cjyuan. I updated the V variable to date to make it more meaningful. also removed the console.logs to make it more clean.

Comment on lines 11 to 27
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

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

test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});
test("should return '24th' for 24", () => {
expect(getOrdinalNumber(24)).toEqual("24th");
});
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});
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 scenarios that cover all possible cases.
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 to make it comprehensive so that the test categories can cover all valid numbers?

Comment on lines 2 to 4
if (count < 0) {
return "Count must be a non-negative integer";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the caller distinguish the result of the following two function calls?

  1. repeat("Count must be a non-negative integer", 1)
  2. repeat("", -1)

Both function calls return the same value.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I see your point. I changed it so it throw error.

Comment on lines 8 to 10
for (let i = 0; i < count; i++) {
return str.repeat(count);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This loop will always iterate exactly once. Do you know why?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. That's because return is inside the loop. so I changed it.

Comment on lines 39 to 44
test("should return a message for negative count", () => {
const str = "error";
const count = -2;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("Count must be a non-negative integer");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If you modified repeat() to throw an error when count is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow(). You can find out more about how to use .toThrow() here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for bring this up. I changed it so it will throw error.

@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 Nov 21, 2025
@PaymanIB
Copy link
Author

Hi @cjyuan , thanks for reviewing my PR. I changed the the code so it covers the points that you mentioned can you please check if they are OK? Thanks and regards.

@PaymanIB PaymanIB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 23, 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.

Can you also revert the changes made to

  • Sprint-2/1-key-erros/0.js
  • Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

and remove Project-CLI-Treasure-Hunt?

function getOrdinalNumber(num) {
return "1st";
const suffixes = ["th", "st", "nd", "rd"];
const date = num % 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why named the variable date? The last two digits do not represent a date.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. yes you are absolutely right! I was in class yesterday and couldn't focus enough. I changed it to a proper Variable name.

Comment on lines 27 to 34
test("append 'th' to numbers ending in 4, except those ending in 14", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect( getOrdinalNumber(24) ).toEqual("24th");
expect( getOrdinalNumber(134) ).toEqual("134th");
});
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests on lines 11-26 are good.

Can you improve the tests on 27-34?

  • Why differentiate numbers ending in 4 from numbers that ending in 14?
  • What about numbers ending in other digits?
  • Why prepare a test just for 11?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I tried to improve the tests on line 27-34. also added a test for other numbers.
11 is exception as it ends with 1 but will get "th", so tested separately.

@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 Nov 23, 2025
@PaymanIB
Copy link
Author

Hi @cjyuan , Many thanks for reviewing my PR. I tried a lot yesterday with the help of 3 volunteers to remove the extras which I don't know how got there in the first place. the best we could do was to made anew branch, which apparently didn't fix the problem. However, as I see those files are all from sprint-3.
I fixed the points you mentioned. can you please check if I've done correctly. kind regards,

@PaymanIB PaymanIB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 23, 2025
Comment on lines 27 to 39
test("append 'th' to numbers ending in 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect( getOrdinalNumber(24) ).toEqual("24th");
expect( getOrdinalNumber(134) ).toEqual("134th");
});
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});
test("append 'th' to numbers which are not ending in 1, 2, 3", () => {
expect(getOrdinalNumber(5)).toEqual("5th");
expect( getOrdinalNumber(29) ).toEqual("29th");
expect( getOrdinalNumber(138) ).toEqual("138th");
});
Copy link
Contributor

@cjyuan cjyuan Nov 23, 2025

Choose a reason for hiding this comment

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

  • Isn't the test categories on 35-39 include numbers ending in 4?

  • If 11 is a special case, then what about 12, 13, 111, 212, etc.?

Copy link
Author

Choose a reason for hiding this comment

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

Now I got it! Thanks for pointing me that way. 11 is already covered and don't need a separate test, as all other numbers do.

Comment on lines 27 to 31
test("append 'th' to numbers which are not ending in 1, 2, 3", () => {
expect(getOrdinalNumber(5)).toEqual("5th");
expect( getOrdinalNumber(29) ).toEqual("29th");
expect( getOrdinalNumber(24) ).toEqual("24th");
expect( getOrdinalNumber(138) ).toEqual("138th");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

All the test categories now cover all numbers, but within this category, the samples being used are not very comprehensive. Can you think of what numbers you could have also tested?

@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. labels Nov 23, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants