-
-
Notifications
You must be signed in to change notification settings - Fork 337
London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | implement and rewrite tests coursework #1261
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?
London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | implement and rewrite tests coursework #1261
Changes from all commits
0c4631a
4a2804d
6b4ee50
7d502dc
82958b5
c286e4a
a70220f
bc11ec7
7eab738
3f7c3f8
6769341
f231516
608f1db
9a3c314
c099074
fa537b2
36e8c14
af851f3
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,33 @@ 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 (undefined) | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| // Special case: both numerator and denominator are zeros (undefined) | ||
| expect(isProperFraction(0, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: numerator is zero (proper fraction) | ||
| test(`should return true for proper fraction`, () => { | ||
|
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. The grouping is good. Could also consider including the condition |
||
| expect(isProperFraction(0, 1)).toEqual(true); | ||
| // case: both values are positive and the value of the numerater is less than the value of the denominater (proper fraction) | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| // case: the value of the numerater is negative and its absolute value is less than the value of the denominater (roper fraction) | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| // case: the value of the denominator is negative and its absolute value is greater than the value of the numerator (proper fraction) | ||
| expect(isProperFraction(1, -2)).toEqual(true); | ||
| // case: both values of the numerator and denominator are negative and the absolute value of the numerator is less than the absolute value of the denominator (proper fraction) | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| }); | ||
|
|
||
| // case: both values are positive and the value of the denominater is less than the value of the numerater (improper fraction) | ||
| test(`should return false for improper fraction`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| // case: the value of the numerater is negative and its absolute value is greater than the value of the denominater (improper fraction) | ||
| expect(isProperFraction(-2, 1)).toEqual(false); | ||
| // case: both values of the numerator and denominator are negative and the absolute value of the numerator is greater than the absolute value of the denominator (improper fraction) | ||
| expect(isProperFraction(-2, -1)).toEqual(false); | ||
| // case: the value of the denominator is negative and its absolute value is less than the value of the numerator (improper fraction) | ||
| expect(isProperFraction(2, -1)).toEqual(false); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,44 @@ const getCardValue = require("../implement/3-get-card-value"); | |
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| expect(getCardValue("A♣")).toEqual(11); | ||
| }); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| test("should return the value of number cards (2-10)", () => { | ||
| expect(getCardValue("2♠")).toEqual(2); | ||
| expect(getCardValue("3♥")).toEqual(3); | ||
| expect(getCardValue("4♦")).toEqual(4); | ||
| expect(getCardValue("5♣")).toEqual(5); | ||
| expect(getCardValue("6♥")).toEqual(6); | ||
| expect(getCardValue("7♠")).toEqual(7); | ||
| expect(getCardValue("8♦")).toEqual(8); | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| expect(getCardValue("10♣")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+17
to
+27
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. I don't think your function can pass this test yet.
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 changed the returned outcome to a number in the function |
||
|
|
||
| // Face Cards (J, Q, K) | ||
| test(`Should return the value of 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 when given an invalid card`, () => { | ||
| expect(() => getCardValue("1♠")).toThrow(); | ||
| expect(() => getCardValue("2❦")).toThrow(); | ||
| expect(() => getCardValue("11♥")).toThrow(); | ||
| expect(() => getCardValue("B♦")).toThrow(); | ||
| expect(() => getCardValue("Z♣")).toThrow(); | ||
| expect(() => getCardValue("♣2")).toThrow(); | ||
| expect(() => getCardValue("s")).toThrow(); | ||
| expect(() => getCardValue("♣♥♠♦")).toThrow(); | ||
| expect(() => getCardValue("")).toThrow(); | ||
| }); | ||
|
|
||
| // 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.