-
-
Notifications
You must be signed in to change notification settings - Fork 337
Manchester | 26-ITP-Jan | Liban Jama | Sprint 3 | Implement and rewrite tests #1197
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 4 commits
1924ef4
a73fa1a
3d438c6
f6f394c
254abc7
1a4482e
aabad30
c555833
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 |
|---|---|---|
|
|
@@ -4,7 +4,43 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); | |
|
|
||
| // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. | ||
|
|
||
| // Special case: numerator is zero | ||
| // Special case: denominator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 2: Proper fractions | ||
| // the numerator is smaller than the denominator, so the fraction is a proper fraction | ||
| test(`should return true when |numerator| < |denominator|`, () => { | ||
| expect(isProperFraction(6, 7)).toEqual(true); | ||
| expect(isProperFraction(2, 4)).toEqual(true); | ||
| }); | ||
|
|
||
| // Case 3: Improper fractions | ||
| // numerator is bigger than denominator, so the fraction is not proper | ||
| test("should return false when numerator is bigger than denominator", () => { | ||
| expect(isProperFraction(8, 6)).toEqual(false); | ||
| expect(isProperFraction(4, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 4: Negative numbers | ||
| // numerator or denominator is negative, but function compares absolute values | ||
| test("should return correct result when numerator or denominator is negative", () => { | ||
| expect(isProperFraction(-5, 9)).toEqual(true); | ||
| expect(isProperFraction(-2, 0)).toEqual(false); | ||
| }); | ||
|
||
|
|
||
| // Case 5: Numerator equals denominator fraction equals 1, so it is not proper | ||
| test("should return false when numerator is equal to denominator", () => { | ||
| expect(isProperFraction(6, 6)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 6: Numerator just less than denominator fraction is slightly below 1, so it is proper | ||
| test("should return true when numerator is just less than denominator", () => { | ||
| expect(isProperFraction(2, 3)).toEqual(true); | ||
| }); | ||
|
|
||
| // Case 7: Numerator greater than denominator fraction is slightly above 1, so it is not proper | ||
| test("should return false when numerator is greater than denominator", () => { | ||
| expect(isProperFraction(6, 5)).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. Have you tested your implementation with this script?
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. yes and it passed
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. Unless you have different files on your computer, I don't see how your function can pass this test. Both the function implementation and the tests have bugs.
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. ok ill fix those bugs, thanks
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. Altered function to pass failing test. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,27 @@ test(`Should return 11 when given an ace card`, () => { | |
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
|
|
||
| // Case 2: Face (J, Q, K) | ||
| test(`Should return 10 when given an face card`, () => { | ||
| expect(getCardValue("J♣")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`Should return 10 when given an face card`, () => { | ||
| expect(getCardValue("Q♦")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`Should return 10 when given an face card`, () => { | ||
| expect(getCardValue("K♥")).toEqual(10); | ||
| }); | ||
| // Case 3: Number Cards (2-10) | ||
| test(`Should return numerical value when given an number card`, () => { | ||
| expect(getCardValue("5")).toEqual(5); | ||
| }); | ||
|
Comment on lines
+29
to
+32
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. Supposedly a valid card is a string in this format: "5" (without the suit character), would be considered an invalid card.
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. Thanks, ive changed that.
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. Function implementation is correct. This test category is supposed for valid number cards. |
||
|
|
||
| test(`Should return error if the card string is invalid`, () => { | ||
| expect(() => getCardValue("17")).toThrow("Error invalid card"); | ||
| }); | ||
|
|
||
| // 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.