-
-
Notifications
You must be signed in to change notification settings - Fork 338
Manchester | 26-ITP-Jan | Farancis Dore Etonkie | Sprint 3 | Module Structuring and testing data #1216
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?
Manchester | 26-ITP-Jan | Farancis Dore Etonkie | Sprint 3 | Module Structuring and testing data #1216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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 tests in this script do not yet cover all cases. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,42 @@ | |
| 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. | ||
| // Example: 1/2 is a proper fraction | ||
| test(`should return true for 1/2`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| }); | ||
| // Example: 2/1 is not a proper fraction | ||
| test(`should return false for 2/1`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| }); | ||
| // Example: -1/2 is a proper fraction | ||
| test(`should return true for -1/2`, () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| }); | ||
| // Example: 1/-2 is a proper fraction | ||
| test(`should return true for 1/-2`, () => { | ||
| expect(isProperFraction(1, -2)).toEqual(true); | ||
| }); | ||
| // Example: -1/-2 is a proper fraction | ||
| test(`should return true for -1/-2`, () => { | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| }); | ||
|
Comment on lines
+6
to
+25
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. It is good that the selected test values cover all combinations of positive and negative values. To make the tests clearer that all fractions that satisfy abs(numerator) < abs(denominator) are proper fractions, we could also express the test as: 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);
}); |
||
| // Example: 0/5 is a proper fraction | ||
| test(`should return true for 0/5`, () => { | ||
| expect(isProperFraction(0, 5)).toEqual(true); | ||
| }); | ||
| // Example: 5/0 is not a proper fraction | ||
| test(`should return false for 5/0`, () => { | ||
| expect(isProperFraction(5, 0)).toEqual(false); | ||
| }); | ||
| // Example: 5/5 is not a proper fraction | ||
| test(`should return false for 5/5`, () => { | ||
| expect(isProperFraction(5, 5)).toEqual(false); | ||
| }); | ||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,27 @@ | |
| const getCardValue = require("../implement/3-get-card-value"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| // Examples: | ||
| test(`should return 9 for "9♠"`, () => { | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| }); | ||
|
|
||
| test(`should return 11 for "A♥"`, () => { | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| }); | ||
|
|
||
| test(`should return 10 for "J♦"`, () => { | ||
| expect(getCardValue("J♦")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`should return 10 for "Q♣"`, () => { | ||
| expect(getCardValue("Q♣")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`should return 10 for "K♠"`, () => { | ||
| expect(getCardValue("K♠")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+15
to
+25
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. When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples. For example, one possible category for Can you practice preparing tests in this fashion? |
||
|
|
||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
|
|
@@ -14,6 +35,7 @@ test(`Should return 11 when given an ace card`, () => { | |
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
|
|
||
|
|
||
| // 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 | ||
|
Comment on lines
36
to
41
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. Can you also implement this test? (Invalid case) |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to break a long comment into multiple lines so that we don't need to scroll horizontally in an editor to view all the comment.