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