|
1 | 1 | import { getCardValue } from "../implement/3-get-card-value.js"; |
2 | 2 |
|
3 | | -// TODO: Write tests in Jest syntax to cover all possible outcomes. |
4 | | - |
5 | | -// Case 1: Ace (A) |
6 | 3 | test(`Should return 11 when given an ace card`, () => { |
7 | 4 | expect(getCardValue("A♠")).toEqual(11); |
| 5 | + expect(getCardValue("A♥")).toEqual(11); |
8 | 6 | }); |
9 | 7 |
|
10 | | -// Suggestion: Group the remaining test data into these categories: |
11 | | -// Number Cards (2-10) |
12 | | -// Face Cards (J, Q, K) |
13 | | -// Invalid Cards |
| 8 | +test(`Should return the number for number cards`, () => { |
| 9 | + expect(getCardValue("2♣")).toEqual(2); |
| 10 | + expect(getCardValue("5♥")).toEqual(5); |
| 11 | + expect(getCardValue("7♠")).toEqual(7); |
| 12 | + expect(getCardValue("10♦")).toEqual(10); |
| 13 | +}); |
14 | 14 |
|
15 | | -// To learn how to test whether a function throws an error as expected in Jest, |
16 | | -// please refer to the Jest documentation: |
17 | | -// https://jestjs.io/docs/expect#tothrowerror |
| 15 | +test(`Should return 10 for face cards`, () => { |
| 16 | + expect(getCardValue("J♠")).toEqual(10); |
| 17 | + expect(getCardValue("Q♥")).toEqual(10); |
| 18 | + expect(getCardValue("K♦")).toEqual(10); |
| 19 | +}); |
18 | 20 |
|
| 21 | +test(`Should throw for invalid cards`, () => { |
| 22 | + expect(() => getCardValue("A")).toThrow(); |
| 23 | + expect(() => getCardValue("♠")).toThrow(); |
| 24 | + expect(() => getCardValue("11♠")).toThrow(); |
| 25 | + expect(() => getCardValue("hello")).toThrow(); |
| 26 | + expect(() => getCardValue("")).toThrow(); |
| 27 | + expect(() => getCardValue("A♠♠")).toThrow(); |
| 28 | +}); |
0 commit comments