-
-
Notifications
You must be signed in to change notification settings - Fork 337
Birmingham | 26-ITP-Jan | Tasleem Adedokun | Sprint 3 | Coursework 3 implement and rewrite #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
21fb023
25f474f
fa92fed
e09c22e
11691ae
0c92b19
d04de54
36634de
0866294
c8cef50
2a0af31
c2ce7b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,30 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); | |
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Case 2: positive proper fractions | ||
| test(`should return true for positive proper fractions (numerator < denominator)`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| expect(isProperFraction(2, 4)).toEqual(true); | ||
| }) | ||
|
|
||
| // Case 3: negative proper fractions | ||
| test(`should return true for negative proper fractions (numerator < denominator)`, () => { | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| expect(isProperFraction(-2, -4)).toEqual(true); | ||
| }) | ||
|
|
||
| // Case 4: improper fractions (numerator >= denominator) | ||
| test(`should return false for improper fractions`, () => { | ||
| expect(isProperFraction(4, 2)).toEqual(false); | ||
| expect(isProperFraction(4, 4)).toEqual(false); | ||
| expect(isProperFraction(-6, 4)).toEqual(false); | ||
| expect(isProperFraction(7, -2)).toEqual(false); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use pseudo-code and notations like
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have done that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cjyuan Thank you very much always. I always appreciate your reviews, and I have implemented all the changes. Thank you very much. |
||
|
|
||
| // Case 5: numerator is zero | ||
| test(`should return true when numerator is 0 and denominator is non-zero`, () => { | ||
| expect(isProperFraction(0, 3)).toEqual(true); | ||
| expect(isProperFraction(0, -5)).toEqual(true); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,25 @@ test(`Should return 11 when given an ace card`, () => { | |
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| test("Should return the correct value for number cards", () => { | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| expect(getCardValue("2♠")).toEqual(2); | ||
| expect(getCardValue("10♦")).toEqual(10); | ||
| }); | ||
|
|
||
|
|
||
| // Face Cards (J, Q, K) | ||
| test("Should return 10 for face cards (J, Q, K)", () => { | ||
| expect(getCardValue("J♠")).toEqual(10); | ||
| expect(getCardValue("Q♠")).toEqual(10); | ||
| expect(getCardValue("K♠")).toEqual(10); | ||
| }); | ||
|
|
||
|
|
||
| // Invalid Cards | ||
| test("Should throw an error for invalid cards", () => { | ||
| expect(() => getCardValue(null)).toThrow(); | ||
| expect(() => getCardValue(undefined)).toThrow(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your code didn't actually checked if the value of card is string or not. Your function would throw a TypeError (kind of an unexpected error) instead of the controlled "Invalid card" error. Including these tests in the test script may send the wrong message that the function should properly check the type of the argument and classify any value that is not a string as "Invalid card". |
||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not test also strings that are not in the expected format?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have now tested for strings. |
||
|
|
||
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.