Skip to content

Commit e99980a

Browse files
committed
test: add comprehensive Jest tests for getCardValue function
1 parent 6ca023a commit e99980a

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,34 @@ test("should return 11 for Ace of Spades", () => {
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+
test("should return correct value for number cards (2-9)", () => {
11+
expect(getCardValue("2♦")).toEqual(2);
12+
expect(getCardValue("3♣")).toEqual(3);
13+
expect(getCardValue("4♥")).toEqual(4);
14+
expect(getCardValue("5♥")).toEqual(5);
15+
expect(getCardValue("6♠")).toEqual(6);
16+
expect(getCardValue("7♦")).toEqual(7);
17+
expect(getCardValue("8♣")).toEqual(8);
18+
expect(getCardValue("9♥")).toEqual(9);
19+
});
20+
21+
test("should return 10 for face cards (J, Q, K, 10)", () => {
22+
expect(getCardValue("10♣")).toEqual(10);
23+
expect(getCardValue("J♦")).toEqual(10);
24+
expect(getCardValue("Q♠")).toEqual(10);
25+
expect(getCardValue("K♥")).toEqual(10);
26+
});
27+
28+
test("should return 11 for all Aces", () => {
29+
expect(getCardValue("A♠")).toEqual(11);
30+
expect(getCardValue("A♥")).toEqual(11);
31+
expect(getCardValue("A♦")).toEqual(11);
32+
expect(getCardValue("A♣")).toEqual(11);
33+
});
34+
35+
test("should throw an error for invalid card rank", () => {
36+
expect(() => getCardValue("X♠")).toThrow("Invalid card rank");
37+
expect(() => getCardValue("Z♥")).toThrow("Invalid card rank");
38+
expect(() => getCardValue("11♦")).toThrow("Invalid card rank");
39+
expect(() => getCardValue("0♣")).toThrow("Invalid card rank");
40+
});

0 commit comments

Comments
 (0)