|
1 | 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 | 2 | const getCardValue = require("../implement/3-get-card-value"); |
4 | 3 |
|
| 4 | +// Case 1: Ace |
5 | 5 | test("should return 11 for Ace of Spades", () => { |
6 | 6 | const aceofSpades = getCardValue("A♠"); |
7 | 7 | expect(aceofSpades).toEqual(11); |
8 | 8 | }); |
9 | 9 |
|
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 | +// Case 2: Handle Number Cards (2–10) |
| 11 | +test("should return numeric value for number cards 2–10", () => { |
| 12 | + expect(getCardValue("2♥")).toEqual(2); |
| 13 | + expect(getCardValue("7♦")).toEqual(7); |
| 14 | + expect(getCardValue("9♣")).toEqual(9); |
| 15 | + expect(getCardValue("10♠")).toEqual(10); |
| 16 | +}); |
| 17 | + |
| 18 | +// Case 3: Handle Face Cards (J, Q, K) |
| 19 | +test("should return 10 for face cards J, Q, K", () => { |
| 20 | + expect(getCardValue("J♠")).toEqual(10); |
| 21 | + expect(getCardValue("Q♦")).toEqual(10); |
| 22 | + expect(getCardValue("K♥")).toEqual(10); |
| 23 | +}); |
| 24 | + |
| 25 | +// Case 4: Handle Ace (A) |
| 26 | +test("should return 11 for any Ace", () => { |
| 27 | + expect(getCardValue("A♣")).toEqual(11); |
| 28 | + expect(getCardValue("A♦")).toEqual(11); |
| 29 | + expect(getCardValue("A♥")).toEqual(11); |
| 30 | +}); |
| 31 | + |
| 32 | +// Case 5: Handle Invalid Cards |
| 33 | +test("should throw an error for invalid card rank", () => { |
| 34 | + expect(() => getCardValue("Z♠")).toThrow("Invalid card rank"); |
| 35 | + expect(() => getCardValue("1♦")).toThrow("Invalid card rank"); |
| 36 | + expect(() => getCardValue("XY")).toThrow("Invalid card rank"); |
| 37 | +}); |
0 commit comments