Skip to content

Commit 56c990b

Browse files
committed
Added tests for getCardValue function covering Aces, Number cards, Face cards, and Invalid cards
1 parent 7e4cb27 commit 56c990b

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

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

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,74 @@ const getCardValue = require("../implement/3-get-card-value");
77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
10+
expect(getCardValue("A♣")).toEqual(11);
11+
expect(getCardValue("A♦")).toEqual(11);
12+
expect(getCardValue("A♥")).toEqual(11);
13+
});
14+
15+
// Case 2: Handle Number Cards (2-10):
16+
test("should return the appropriate number from 2 to 10", () => {
17+
expect(getCardValue("2♥")).toEqual(2);
18+
expect(getCardValue("3♥")).toEqual(3);
19+
expect(getCardValue("4♥")).toEqual(4);
20+
expect(getCardValue("5♥")).toEqual(5);
21+
expect(getCardValue("6♥")).toEqual(6);
22+
expect(getCardValue("7♥")).toEqual(7);
23+
expect(getCardValue("8♥")).toEqual(8);
24+
expect(getCardValue("9♥")).toEqual(9);
25+
expect(getCardValue("10♥")).toEqual(10);
26+
expect(getCardValue("2♠")).toEqual(2);
27+
expect(getCardValue("3♠")).toEqual(3);
28+
expect(getCardValue("4♠")).toEqual(4);
29+
expect(getCardValue("5♠")).toEqual(5);
30+
expect(getCardValue("6♠")).toEqual(6);
31+
expect(getCardValue("7♠")).toEqual(7);
32+
expect(getCardValue("8♠")).toEqual(8);
33+
expect(getCardValue("9♠")).toEqual(9);
34+
expect(getCardValue("10♠")).toEqual(10);
35+
expect(getCardValue("2♦")).toEqual(2);
36+
expect(getCardValue("3♦")).toEqual(3);
37+
expect(getCardValue("4♦")).toEqual(4);
38+
expect(getCardValue("5♦")).toEqual(5);
39+
expect(getCardValue("6♦")).toEqual(6);
40+
expect(getCardValue("7♦")).toEqual(7);
41+
expect(getCardValue("8♦")).toEqual(8);
42+
expect(getCardValue("9♦")).toEqual(9);
43+
expect(getCardValue("10♦")).toEqual(10);
44+
expect(getCardValue("2♣")).toEqual(2);
45+
expect(getCardValue("3♣")).toEqual(3);
46+
expect(getCardValue("4♣")).toEqual(4);
47+
expect(getCardValue("5♣")).toEqual(5);
48+
expect(getCardValue("6♣")).toEqual(6);
49+
expect(getCardValue("7♣")).toEqual(7);
50+
expect(getCardValue("8♣")).toEqual(8);
51+
expect(getCardValue("9♣")).toEqual(9);
52+
expect(getCardValue("10♣")).toEqual(10);
53+
});
54+
55+
// Case 3: Handle Face Cards (J, Q, K):
56+
test("should return 10 for face cards", () => {
57+
expect(getCardValue("J♠")).toEqual(10);
58+
expect(getCardValue("Q♠")).toEqual(10);
59+
expect(getCardValue("K♠")).toEqual(10);
60+
expect(getCardValue("J♦")).toEqual(10);
61+
expect(getCardValue("Q♦")).toEqual(10);
62+
expect(getCardValue("K♦")).toEqual(10);
63+
expect(getCardValue("J♣")).toEqual(10);
64+
expect(getCardValue("Q♣")).toEqual(10);
65+
expect(getCardValue("K♣")).toEqual(10);
66+
expect(getCardValue("J♥")).toEqual(10);
67+
expect(getCardValue("Q♥")).toEqual(10);
68+
expect(getCardValue("K♥")).toEqual(10);
69+
});
70+
71+
// Case 4: Handle Invalid Cards:
72+
test("Should return 'Invalid card rank.' for invalid cards", () => {
73+
expect(() => getCardValue("KJ")).toThrow("Invalid card rank.");
74+
expect(() => getCardValue("AK")).toThrow("Invalid card rank.");
75+
expect(() => getCardValue(" ")).toThrow("Invalid card rank.");
76+
expect(() => getCardValue("S♠")).toThrow("Invalid card rank.");
77+
expect(() => getCardValue("J♠♠")).toThrow("Invalid card rank.");
1078
});
1179

1280
// Suggestion: Group the remaining test data into these categories:
@@ -17,4 +85,3 @@ test(`Should return 11 when given an ace card`, () => {
1785
// To learn how to test whether a function throws an error as expected in Jest,
1886
// please refer to the Jest documentation:
1987
// https://jestjs.io/docs/expect#tothrowerror
20-

0 commit comments

Comments
 (0)