|
1 | 1 | import { getCardValue } from "../implement/3-get-card-value.js"; |
2 | 2 |
|
3 | | -test("Should return 2 for a number card", () => { |
| 3 | +test("Should return the correct value for number cards", () => { |
4 | 4 | expect(getCardValue("2♥")).toEqual(2); |
5 | | -}); |
6 | | - |
7 | | -test("Number card (2-10)", () => { |
8 | | - expect(getCardValue("7♦")).toEqual(7); |
| 5 | + expect(getCardValue("3♠")).toEqual(3); |
9 | 6 | expect(getCardValue("4♣")).toEqual(4); |
| 7 | + expect(getCardValue("5♦")).toEqual(5); |
| 8 | + expect(getCardValue("6♥")).toEqual(6); |
| 9 | + expect(getCardValue("7♦")).toEqual(7); |
| 10 | + expect(getCardValue("8♣")).toEqual(8); |
| 11 | + expect(getCardValue("9♠")).toEqual(9); |
| 12 | + expect(getCardValue("10♥")).toEqual(10); |
10 | 13 | }); |
11 | 14 |
|
12 | | -test("Face Cards (J, Q, K)", () => { |
| 15 | +test("Should return 10 for face cards", () => { |
13 | 16 | expect(getCardValue("J♣")).toEqual(10); |
14 | 17 | expect(getCardValue("Q♦")).toEqual(10); |
15 | 18 | expect(getCardValue("K♥")).toEqual(10); |
16 | 19 | }); |
17 | 20 |
|
18 | | -// Case 1: Ace (A) |
19 | | -test(`Should return 11 when given an ace card`, () => { |
| 21 | +test("Should return 11 for an ace of any suit", () => { |
20 | 22 | expect(getCardValue("A♠")).toEqual(11); |
| 23 | + expect(getCardValue("A♥")).toEqual(11); |
| 24 | + expect(getCardValue("A♦")).toEqual(11); |
| 25 | + expect(getCardValue("A♣")).toEqual(11); |
| 26 | +}); |
| 27 | + |
| 28 | +test("Should throw an error for an invalid rank", () => { |
| 29 | + expect(() => getCardValue("X♠")).toThrow( |
| 30 | + 'Expected a number followed by a suit, but got "X♠"' |
| 31 | + ); |
| 32 | +}); |
| 33 | + |
| 34 | +test("Should throw an error for an invalid suit", () => { |
| 35 | + expect(() => getCardValue("9x")).toThrow( |
| 36 | + 'Expected a number followed by a suit, but got "9x"' |
| 37 | + ); |
21 | 38 | }); |
22 | 39 |
|
23 | | -test("Invalid cards throw an error", () => { |
24 | | - expect(() => getCardValue("2x")).toThrow(); |
25 | | - expect(() => getCardValue(invalid)).toThrow(); |
| 40 | +test("Should throw an error for malformed input", () => { |
| 41 | + expect(() => getCardValue("invalid")).toThrow( |
| 42 | + 'Expected a number followed by a suit, but got "invalid"' |
| 43 | + ); |
26 | 44 | }); |
27 | 45 |
|
28 | 46 | // Suggestion: Group the remaining test data into these categories: |
|
0 commit comments