Skip to content

Commit 16959cf

Browse files
committed
added two test cases for implement
1 parent 3e84b0b commit 16959cf

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
// This statement loads the isProperFraction function you wrote in the implement directory.
2-
// We will use the same function, but write tests for it using Jest in this file.
31
const isProperFraction = require("../implement/2-is-proper-fraction");
42

53
test("should return true for a proper fraction", () => {
64
expect(isProperFraction(2, 3)).toEqual(true);
75
});
86

97
// Case 2: Identify Improper Fractions:
8+
test("should return false for improper fractions (numerator >= denominator)", () => {
9+
expect(isProperFraction(5, 2)).toEqual(false); // 5/2
10+
expect(isProperFraction(7, 3)).toEqual(false); // 7/3
11+
});
1012

1113
// Case 3: Identify Negative Fractions:
14+
test("should correctly handle negative fractions using absolute value of numerator", () => {
15+
expect(isProperFraction(-4, 7)).toEqual(true); // |−4| < 7 → proper
16+
expect(isProperFraction(-5, 2)).toEqual(false); // |−5| >= 2 → improper
17+
});
1218

1319
// Case 4: Identify Equal Numerator and Denominator:
20+
test("should return false when numerator equals denominator", () => {
21+
expect(isProperFraction(3, 3)).toEqual(false); // 3/3
22+
expect(isProperFraction(-6, -6)).toEqual(false); // -6/-6
23+
});
Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
// This statement loads the getCardValue function you wrote in the implement directory.
2-
// We will use the same function, but write tests for it using Jest in this file.
32
const getCardValue = require("../implement/3-get-card-value");
43

4+
// Case 1: Ace
55
test("should return 11 for Ace of Spades", () => {
66
const aceofSpades = getCardValue("A♠");
77
expect(aceofSpades).toEqual(11);
88
});
99

10-
// Case 2: Handle Number Cards (2-10):
11-
// Case 3: Handle Face Cards (J, Q, K):
12-
// Case 4: Handle Ace (A):
13-
// Case 5: Handle Invalid Cards:
10+
// Case 2: Handle Number Cards (2–10)
11+
test("should return numeric value for number cards 2–10", () => {
12+
expect(getCardValue("2♥")).toEqual(2);
13+
expect(getCardValue("7♦")).toEqual(7);
14+
expect(getCardValue("9♣")).toEqual(9);
15+
expect(getCardValue("10♠")).toEqual(10);
16+
});
17+
18+
// Case 3: Handle Face Cards (J, Q, K)
19+
test("should return 10 for face cards J, Q, K", () => {
20+
expect(getCardValue("J♠")).toEqual(10);
21+
expect(getCardValue("Q♦")).toEqual(10);
22+
expect(getCardValue("K♥")).toEqual(10);
23+
});
24+
25+
// Case 4: Handle Ace (A)
26+
test("should return 11 for any Ace", () => {
27+
expect(getCardValue("A♣")).toEqual(11);
28+
expect(getCardValue("A♦")).toEqual(11);
29+
expect(getCardValue("A♥")).toEqual(11);
30+
});
31+
32+
// Case 5: Handle Invalid Cards
33+
test("should throw an error for invalid card rank", () => {
34+
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank");
35+
expect(() => getCardValue("1♦")).toThrow("Invalid card rank");
36+
expect(() => getCardValue("XY")).toThrow("Invalid card rank");
37+
});

0 commit comments

Comments
 (0)