Repository navigation
Conversation
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.
…g () => in my thrown error tests
hackertainment
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
This is correct but can be just using else to include the rest of the values.
| // - "Invalid angle" for angles outside the valid range. | ||
| test("Classifies Invalid angles", () => { | ||
| const right = getAngleType(360); | ||
| assert.equal(right, "Invalid angle"); | ||
| }); |
There was a problem hiding this comment.
There should be one more boundary case for invalid angle. Can you think of it? Please add it back. Thank you.
| 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"); | ||
| }); |
There was a problem hiding this comment.
There should be two boundary cases in this test suite. Can you think of them? Please add them. Thank you.
| 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); | ||
| }); |
There was a problem hiding this comment.
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.
| // 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); | ||
| }); |
There was a problem hiding this comment.
There should be two more negative test suites and two zero related test suites. Please add them back. Thank you.
| let suit = card.slice(-1); | ||
| let cardNumber = card.slice(0, -1); | ||
| let value = Number(cardNumber); | ||
|
|
||
| if (card.length >= 4) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
have you tested it? I don't think it is correct. Please fix this bug. Thank you.
There was a problem hiding this comment.
Both valid and invalid cards, there should be more test cases covering various combinations. Please add them. Thank you.
| // 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"); | ||
| }); |
There was a problem hiding this comment.
There should be more test cases for invalid cards. Please add them. Thank you.
Learners, PR Template
Self checklist
Task code
CYF-1059.
Changelist
I built code while writing tests for the code using node and jest to test.