Skip to content

Manchester | 26-ITP-Sept | Fatima Rouchi | Sprint 2 | Implement and rewrite tests - #1728

Open
fatimarouchi wants to merge 11 commits into
CodeYourFuture:mainfrom
fatimarouchi:coursework/sprint-3-implement-and-rewrite
Open

fatimarouchi wants to merge 11 commits into
CodeYourFuture:mainfrom
fatimarouchi:coursework/sprint-3-implement-and-rewrite

Conversation

@fatimarouchi

Copy link
Copy Markdown

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

##CYF-1059

@fatimarouchi fatimarouchi changed the title Manchester | 26-ITP-Sept | Fatima Rouchi| Sprint 2 | Implement and rewrite tests Manchester | 26-ITP-Sept | Fatima Rouchi | Sprint 2 | Implement and rewrite tests Oct 17, 2026
@fatimarouchi fatimarouchi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 17, 2026
@cjyuan cjyuan 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 23, 2026
Comment on lines +41 to +46

const value = Number(rank);

if (!isNaN(value) && value >= 2 && value <= 10) {
return value;
}

Copy link
Copy Markdown
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 "0002".

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

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("0002♠");

});
// Case 6: Invalid angles

test('should return "Invalid angle" for invalid angles', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An exact range of invalid angles could probably make the test description more informative.

Comment on lines +25 to +27
test("should return false for negative numerator and denominator", () => {
expect(isProperFraction(-1, -2)).toEqual(false);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May I ask which authoritative source you used for the definition of a proper fraction?

In math

  • $\frac{-1}{2}$ and $\frac{1}{-2}$ equals $-\frac{1}{2}$
  • $\frac{-1}{-2}$ equals $\frac{1}{2}$


test("Should return 10 when given a 10 card", () => {
expect(getCardValue("10♠")).toEqual(10);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual rank, we will need about 13 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.

For example, one possible category for getCardValue() is, "should return the value of number cards (2-10)", and we can prepare the test as

test("should return the value of number cards (2-10)", () => {
    expect(getCardValue("2♣︎")).toEqual(2);
    expect(getCardValue("5♠")).toEqual(5);
    expect(getCardValue("10♥")).toEqual(10);
    // Note: We could also use a loop to check all values from 2 to 10.
});

Can you practice preparing tests in this fashion?

Comment on lines +32 to +38
test("Should throw an error for invalid text", () => {
expect(() => getCardValue("invalid")).toThrow();
});

test("Should throw an error when suit is missing", () => {
expect(() => getCardValue("A")).toThrow();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When testing invalid inputs, focus on edge cases that the function might overlook. Inputs that closely resemble valid card values are especially useful. For example, "A" is a good test case because it contains a valid rank but is missing the suit character.

Can you think of other test cases that resemble valid card values but are still invalid?

An empty string ("") is also always worth testing for any parameter that accepts a string.

Comment on lines +32 to +36
test("classifies invalid negative angles", () => {
const invalid = getAngleType(-10);
assert.equal(invalid, "Invalid angle");
});
test("classifies angles greater than 360 as invalid", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note:

  • Negative angles means angle < 0 but 0 is also invalid. So you could consider specifying when angle <= 0 instead.

  • The description "greater than 360" does not include 360. >= 360 is "greater than or equal to 360".

@cjyuan cjyuan 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 23, 2026
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