|
3 | 3 | const getCardValue = require("../implement/3-get-card-value"); |
4 | 4 |
|
5 | 5 | test("should return 11 for Ace of Spades", () => { |
6 | | - const aceofSpades = getCardValue("A♠"); |
7 | | - expect(aceofSpades).toEqual(11); |
| 6 | + const aceOfSpades = getCardValue("A♠"); |
| 7 | + expect(aceOfSpades).toEqual(11); |
8 | 8 | }); |
9 | 9 |
|
10 | 10 | // Case 2: Handle Number Cards (2-10): |
| 11 | +test("should return same number for number cards", () => { |
| 12 | + const cards = [ |
| 13 | + ["2♥", 2], |
| 14 | + ["3♣", 3], |
| 15 | + ["4♦", 4], |
| 16 | + ["5♠", 5], |
| 17 | + ["6♥", 6], |
| 18 | + ["7♣", 7], |
| 19 | + ["8♦", 8], |
| 20 | + ["9♠", 9], |
| 21 | + ["10♥", 10], |
| 22 | + ]; |
| 23 | + |
| 24 | + for (const [card, expectedValue] of cards) { |
| 25 | + expect(getCardValue(card)).toEqual(expectedValue); |
| 26 | + } |
| 27 | +}); |
| 28 | + |
11 | 29 | // Case 3: Handle Face Cards (J, Q, K): |
12 | | -// Case 4: Handle Ace (A): |
| 30 | +test("should return 10 for face cards", () => { |
| 31 | + const cards = ["J♦", "K♥", "Q♠"]; |
| 32 | + |
| 33 | + for (const card of cards) { |
| 34 | + expect(getCardValue(card)).toEqual(10); |
| 35 | + } |
| 36 | +}); |
| 37 | + |
| 38 | +// // Case 4: Handle Ace (A): |
| 39 | +test("should return 11 for Ace of Diamonds", () => { |
| 40 | + const aceOfDiamonds = getCardValue("A♦"); |
| 41 | + expect(aceOfDiamonds).toEqual(11); |
| 42 | +}); |
| 43 | + |
13 | 44 | // Case 5: Handle Invalid Cards: |
| 45 | +test("should throw error for invalid card rank", () => { |
| 46 | + expect(() => { |
| 47 | + getCardValue("A"); |
| 48 | + }).toThrow("Invalid card rank."); |
| 49 | +}); |
0 commit comments