Skip to content

Commit 390b390

Browse files
authored
Rewrite tests for getCardValue using Jest
Updated test cases for getCardValue function to use Jest syntax, covering all card types including Aces, number cards, face cards, and invalid cards.
1 parent 4ab6f5c commit 390b390

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
// 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.
3-
const getCardValue = require("../implement/3-get-card-value");
4-
5-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
61

72
// Case 1: Ace (A)
8-
test(`Should return 11 when given an ace card`, () => {
3+
test("should return 11 when given an ace card", () => {
94
expect(getCardValue("A♠")).toEqual(11);
105
});
116

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
7+
// Case 2: Number cards (2-10)
8+
test("should return the numeric value for number cards", () => {
9+
expect(getCardValue("2♥")).toEqual(2);
10+
expect(getCardValue("5♣")).toEqual(5);
11+
expect(getCardValue("9♦")).toEqual(9);
12+
expect(getCardValue("10♠")).toEqual(10);
13+
});
1614

17-
// To learn how to test whether a function throws an error as expected in Jest,
18-
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
15+
// Case 3: Face cards (J, Q, K)
16+
test("should return 10 for face cards", () => {
17+
expect(getCardValue("J♠")).toEqual(10);
18+
expect(getCardValue("Q♥")).toEqual(10);
19+
expect(getCardValue("K♦")).toEqual(10);
20+
});
21+
22+
// Case 4: Invalid cards
23+
test("should throw an error for invalid cards", () => {
24+
expect(() => getCardValue("invalid")).toThrow();
25+
expect(() => getCardValue("1♠")).toThrow();
26+
expect(() => getCardValue("11♠")).toThrow();
27+
expect(() => getCardValue("A")).toThrow();
28+
expect(() => getCardValue("♠")).toThrow();
29+
expect(() => getCardValue("KH")).toThrow();
30+
expect(() => getCardValue("")).toThrow();
31+
});
2032

0 commit comments

Comments
 (0)