Skip to content

Conversation

@asaniDev
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

Created tests to check the expected output of functions before they are created.

@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 27, 2025
Comment on lines 1 to 11
function countChar(stringOfCharacters, findCharacter) {
return 5
let pattern = new RegExp(findCharacter, "g");

let matchingChars = stringOfCharacters.match(pattern);

if (matchingChars === null) {
return 0;
}

return matchingChars.length;
}
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 returns the value you expect in the following function calls?

countChar("=^.^=", "^");
countChar("=^.^=", ".");

Comment on lines +2 to +11
if (num === 1) {
return "1st";
} else if (num === 2) {
return "2nd";
} else if (num === 3) {
console.log(num);
return "3rd";
} else if (num > 3 || num < 21) {
return `${num}th`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • For best practices, code submitted to review should be free of debugging code (to keep the code clean).

  • What should the ordinal numbers of 103, 213, 31 be?

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

test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
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 make the tests in this script more comprehensive?

if (count === 0) {
return newStr;
} else if (count === 1) {
return (newStr += str);
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 just return str directly?

Comment on lines +13 to +15
} else {
return "Error invalid count used, please use integers from 0 upwards.";
}
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("Error invalid count used, please use integers from 0 upwards.", 1)
  2. repeat("", -1)

Both function calls return the same value.

Comment on lines +49 to +51
expect(repeatedStr).toEqual(
"Error invalid count used, please use integers from 0 upwards."
);
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)

@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 Oct 31, 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 with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants