Skip to content

London | 26-Sept | Hugh Mills | Sprint 2 | Implement and rewrite tests - #1670

Open
HM-127BTY wants to merge 30 commits into
CodeYourFuture:mainfrom
HM-127BTY:coursework/sprint-2-implement-and-rewrite
Open

HM-127BTY wants to merge 30 commits into
CodeYourFuture:mainfrom
HM-127BTY:coursework/sprint-2-implement-and-rewrite

Conversation

@HM-127BTY

Copy link
Copy Markdown

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

Task code

CYF-1059.

Changelist

I built code while writing tests for the code using node and jest to test.

added in code for checks for J Q K and A
valid single digit card
Arbitrary non-card string
Incorrect suit
Copied test code for other angles.
Added in test for Basic proper fraction: Numerator < Denominator
Added code for Number cards 2-10
fixed error on numbered cards.
@HM-127BTY HM-127BTY added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 9, 2026
@hackertainment hackertainment 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 9, 2026

@hackertainment hackertainment left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for your coursework. Just need to design test cases that should be enough to cover different combination of values. Please keep it up.

return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
} else if (angle <= 0 || angle >= 360) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is correct but can be just using else to include the rest of the values.

Comment on lines +33 to +37
// - "Invalid angle" for angles outside the valid range.
test("Classifies Invalid angles", () => {
const right = getAngleType(360);
assert.equal(right, "Invalid angle");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be one more boundary case for invalid angle. Can you think of it? Please add it back. Thank you.

Comment on lines +35 to +39
test(`should return "Invalid angle" when (0 > angle > 360)`, () => {
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(396)).toEqual("Invalid angle");
expect(getAngleType(-57)).toEqual("Invalid angle");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be two boundary cases in this test suite. Can you think of them? Please add them. Thank you.

Comment on lines +22 to +32
test("Improper fraction: Denominator = 0", () => {
assert.equal(isProperFraction(1, 0), false);
});

test("Proper fraction with negative number: -Numerator < Denominator", () => {
assert.equal(isProperFraction(-1, 2), true);
});

test("Improper fraction with negative number: -Numerator > Denominator", () => {
assert.equal(isProperFraction(-2, 1), false);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be 3 more test suites related to either zero or negative values. Can you think of them? Please add them back. Thank you.

Comment on lines +31 to +43
// Special case: Proper fraction with negative number: -Numerator < Denominator
test(`should return true when: -Numerator < Denominator`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(-6, 8)).toEqual(true);
expect(isProperFraction(-10, 20)).toEqual(true);
});

// Special case: Improper fraction with negative number: -Numerator > Denominator
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(-5, 4)).toEqual(false);
expect(isProperFraction(-20, 10)).toEqual(false);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be two more negative test suites and two zero related test suites. Please add them back. Thank you.

Comment on lines +28 to +32
let suit = card.slice(-1);
let cardNumber = card.slice(0, -1);
let value = Number(cardNumber);

if (card.length >= 4) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since card.slice() is done before checking card.length, the slice may not work for some lengths. Please fix this issue. Thank you.

return 11;
} else if (value >= 2 && value <= 10) {
return value;
} else if (Value > 10) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

have you tested it? I don't think it is correct. Please fix this bug. Thank you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both valid and invalid cards, there should be more test cases covering various combinations. Please add them. Thank you.

Comment on lines +27 to +46
// Invalid Cards
test(`Should throw error 'expected a number followed by a suit, but got "invalid"' with invalid card`, () => {
expect(() => getCardValue("120♥")).toThrow;
new Error('expected a number followed by a suit, but got "invalid"');
expect(() => getCardValue("203♦")).toThrow;
new Error('expected a number followed by a suit, but got "invalid"');
});
// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

test(`Should throw error "Incorrect suit given" when given wrong symbol"`, () => {
expect(() => getCardValue("2☺")).toThrow;
new Error("Incorrect suit given");
});

test(`Should throw error "Incorrect card number given" when given wrong 2 digit number"`, () => {
expect(() => getCardValue("25♠")).toThrow;
new Error("Incorrect card given");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be more test cases for invalid cards. Please add them. Thank you.

@hackertainment hackertainment 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 9, 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. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants