Skip to content

Commit 0110eec

Browse files
committed
complete 3-get-card-value with jest
1 parent 4c7828e commit 0110eec

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,47 @@
33
const getCardValue = require("../implement/3-get-card-value");
44

55
test("should return 11 for Ace of Spades", () => {
6-
const aceofSpades = getCardValue("A♠");
7-
expect(aceofSpades).toEqual(11);
6+
const aceOfSpades = getCardValue("A♠");
7+
expect(aceOfSpades).toEqual(11);
88
});
99

1010
// Case 2: Handle Number Cards (2-10):
11+
test("should return same number for number cards", () => {
12+
const cards = [
13+
["2♥", 2],
14+
["3♣", 3],
15+
["4♦", 4],
16+
["5♠", 5],
17+
["6♥", 6],
18+
["7♣", 7],
19+
["8♦", 8],
20+
["9♠", 9],
21+
["10♥", 10],
22+
];
23+
24+
for (const [card, expectedValue] of cards) {
25+
expect(getCardValue(card)).toEqual(expectedValue);
26+
}
27+
});
28+
1129
// Case 3: Handle Face Cards (J, Q, K):
12-
// Case 4: Handle Ace (A):
30+
test("should return 10 for face cards", () => {
31+
const cards = ["J♦", "K♥", "Q♠"];
32+
33+
for (const card of cards) {
34+
expect(getCardValue(card)).toEqual(10);
35+
}
36+
});
37+
38+
// // Case 4: Handle Ace (A):
39+
test("should return 11 for Ace of Diamonds", () => {
40+
const aceOfDiamonds = getCardValue("A♦");
41+
expect(aceOfDiamonds).toEqual(11);
42+
});
43+
1344
// Case 5: Handle Invalid Cards:
45+
test("should throw error for invalid card rank", () => {
46+
expect(() => {
47+
getCardValue("A");
48+
}).toThrow("Invalid card rank.");
49+
});

0 commit comments

Comments
 (0)