-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | ITP-Jan-26| Mona_Eltantawy | Sprint 3 | Sprint 3/ implement and testing data #1280
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 all commits
646d6a5
bc93560
9f2ebc3
8f148b8
e7d0002
bbf99ca
7b922da
7adde95
9d68b4e
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 |
|---|---|---|
| @@ -1,10 +1,41 @@ | ||
| // This statement loads the isProperFraction function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| 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. | ||
| // denominator is zero | ||
| test("should return false when denominator is zero", () => { | ||
| expect(isProperFraction(1, 0)).toBe(false); | ||
| }); | ||
|
|
||
| // proper fraction | ||
| test("should return true when numerator < denominator", () => { | ||
| expect(isProperFraction(1, 2)).toBe(true); | ||
| }); | ||
|
|
||
| // improper fraction | ||
| test("should return false when numerator > denominator", () => { | ||
| expect(isProperFraction(5, 3)).toBe(false); | ||
| }); | ||
|
|
||
| // equal numbers | ||
| test("should return false when numerator === denominator", () => { | ||
| expect(isProperFraction(4, 4)).toBe(false); | ||
| }); | ||
|
|
||
| // numerator is zero | ||
| test("should return true when numerator is zero and denominator is positive", () => { | ||
| expect(isProperFraction(0, 5)).toBe(true); | ||
| }); | ||
|
|
||
| // negative numerator | ||
| test("should return false when numerator is negative", () => { | ||
| expect(isProperFraction(-2, 4)).toBe(false); | ||
| }); | ||
|
|
||
| // negative denominator | ||
| test("should return false when denominator is negative", () => { | ||
| expect(isProperFraction(5, -4)).toBe(false); | ||
| }); | ||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| // both negative | ||
| test("should return false when both numerator and denominator are negative", () => { | ||
| expect(isProperFraction(-3, -5)).toBe(false); | ||
| }); | ||
|
Comment on lines
+29
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 your function pass all these tests? 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 fixed the function to pass all the tests |
||
|
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. This file should contain the tests for
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. done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,46 @@ | ||
| // This statement loads the getCardValue function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const getCardValue = require("../implement/3-get-card-value"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| // Ace | ||
| test("Should return 11 when given an ace card", () => { | ||
| expect(getCardValue("A♠")).toBe(11); | ||
| }); | ||
|
|
||
| // Number cards | ||
| test("Should return the numeric value for number cards", () => { | ||
| expect(getCardValue("2♠")).toBe(2); | ||
| expect(getCardValue("5♥")).toBe(5); | ||
| expect(getCardValue("9♦")).toBe(9); | ||
| expect(getCardValue("10♣")).toBe(10); | ||
| }); | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| // Face cards | ||
| test("Should return 10 for face cards", () => { | ||
| expect(getCardValue("J♠")).toBe(10); | ||
| expect(getCardValue("Q♥")).toBe(10); | ||
| expect(getCardValue("K♦")).toBe(10); | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
| // Invalid cards (basic) | ||
| test("Should throw error for invalid cards", () => { | ||
| expect(() => getCardValue("1♠")).toThrow(); | ||
| expect(() => getCardValue("B♣")).toThrow(); | ||
| expect(() => getCardValue("10?")).toThrow(); | ||
| expect(() => getCardValue("invalid")).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 | ||
| // Invalid numeric formats (IMPORTANT for your strict function) | ||
| test("Should throw error for malformed numeric ranks", () => { | ||
| expect(() => getCardValue("0x02♠")).toThrow(); | ||
| expect(() => getCardValue("2.1♠")).toThrow(); | ||
| expect(() => getCardValue("0002♠")).toThrow(); | ||
| }); | ||
|
|
||
| // Invalid structure cases | ||
| test("Should throw error for malformed card structure", () => { | ||
| expect(() => getCardValue("")).toThrow(); | ||
| expect(() => getCardValue("♠")).toThrow(); | ||
| expect(() => getCardValue("10")).toThrow(); | ||
| expect(() => getCardValue("A♠♠")).toThrow(); | ||
| expect(() => getCardValue(" 2♠")).toThrow(); | ||
| expect(() => getCardValue("2♠ ")).toThrow(); | ||
| }); |
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.
360 is also an invalid angle. The test description could include it too.
Why not test both boundary cases?
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.
I added the boundary cases
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.
You didn't update the test description.