Repository navigation
London | 26-ITP-Sep | Mars Adesina | Sprint 2 | Implement and rewrite tests - #1718
marscancode wants to merge 28 commits into
Conversation
| @@ -1,3 +1,3 @@ | |||
| import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | |||
|
|
|||
| // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. | |||
There was a problem hiding this comment.
The test cases in this script do not yet include cases involving negative numbers.
Are
There was a problem hiding this comment.
I've now included tests for negative numbers. Thankyou!
| test("Arbitrary non-card string", () => { | ||
| expect(() => getCardValue("invalid")).toThrow( | ||
| /Expected a valid number followed by a suit, but got "invalid"/ | ||
| ); |
There was a problem hiding this comment.
Why test the error message as
expect(() => getCardValue("invalid")).toThrow(
/Expected a valid number followed by a suit, but got "invalid"/
);instead of as
expect(() => getCardValue("invalid")).toThrow(
'Expected a valid number followed by a suit, but got "invalid"'
);?
There was a problem hiding this comment.
For some reason, I thought this was the syntax used when using .toThrow in jest but i will update with the correct syntax now. Thankyou!
There was a problem hiding this comment.
Could you use an AI to find out
- The difference and similarity between these two types of argument when using Jest's
expect.toThrow()? - How to perform an exact match of the error message with Jest
expect.toThrow()?
There was a problem hiding this comment.
Tests are very comprehensive. Excellent job.
| @@ -1,3 +1,4 @@ | |||
| import { get } from "node:http"; | |||
There was a problem hiding this comment.
Why import get? Where is it used?
| test(`proper fraction with a negative numerator but positive denominator`, () => { | ||
| expect(isProperFraction(-2, 3)).toEqual(true); | ||
| }); | ||
|
|
||
| test(`proper fraction with a positive numerator but negative denominator`, () => { | ||
| expect(isProperFraction(2, -3)).toEqual(true); | ||
| }); | ||
|
|
||
| test(`proper fraction with both a negative numerator and denominator`, () => { | ||
| expect(isProperFraction(-2, -3)).toEqual(true); | ||
| }); |
There was a problem hiding this comment.
Note: Rather than writing a separate test for each sign combination, you could consider grouping inputs that exercise the same behaviour into one test, under a test description that is applicable to all. For example,
test("should return true when abs(numerator) < abs(denominator)", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-1, -2)).toEqual(true);
});Note: Use of widely recognised pseudo-code and math notations like abs(...) or | ... | in the descriptions is an usually accepted.
No change required
Learners, PR Template
Self checklist
Task code
CYF-1059
Changelist
I implemented the three functions:
I also created tests in Node and Jest for all three functions.