Skip to content

Commit 48444ef

Browse files
committed
Add tests for getCardValue covering number cards, face cards, and invalid input
1 parent 057740b commit 48444ef

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
const getCardValue = require("./3-get-card-value");
22

33
test("should return 11 for Ace of Spades", () => {
4-
const aceofSpades = getCardValue("A♠");
5-
expect(aceofSpades).toEqual(11);
6-
});
7-
8-
// Case 2: Handle Number Cards (2-10):
9-
// Case 3: Handle Face Cards (J, Q, K):
10-
// Case 4: Handle Ace (A):
11-
// Case 5: Handle Invalid Cards:
4+
expect(getCardValue("A♠")).toEqual(11);
5+
});
6+
7+
// Case 2: Handle Number Cards (2-10)
8+
test("should return 5 for Five of Hearts", () => {
9+
expect(getCardValue("5♥")).toEqual(5);
10+
});
11+
12+
test("should return 10 for Ten of Diamonds", () => {
13+
expect(getCardValue("10♦")).toEqual(10);
14+
});
15+
16+
// Case 3: Handle Face Cards (J, Q, K)
17+
test("should return 10 for Jack of Clubs", () => {
18+
expect(getCardValue("J♣")).toEqual(10);
19+
});
20+
21+
test("should return 10 for Queen of Spades", () => {
22+
expect(getCardValue("Q♠")).toEqual(10);
23+
});
24+
25+
test("should return 10 for King of Hearts", () => {
26+
expect(getCardValue("K♥")).toEqual(10);
27+
});
28+
29+
// Case 5: Handle Invalid Cards
30+
test("should throw an error for invalid card rank", () => {
31+
expect(() => getCardValue("Z♣")).toThrow("Invalid card rank");
32+
});
33+

0 commit comments

Comments
 (0)