|
1 | 1 | import { getCardValue } from "../implement/3-get-card-value.js"; |
2 | 2 |
|
3 | | -test("Returns the correct value for every valid rank and suit", () => { |
4 | | - const expectedValues = { |
5 | | - A: 11, |
6 | | - 2: 2, |
7 | | - 3: 3, |
8 | | - 4: 4, |
9 | | - 5: 5, |
10 | | - 6: 6, |
11 | | - 7: 7, |
12 | | - 8: 8, |
13 | | - 9: 9, |
14 | | - 10: 10, |
15 | | - J: 10, |
16 | | - Q: 10, |
17 | | - K: 10, |
18 | | - }; |
| 3 | +test("Returns the value of number cards from 2 to 10", () => { |
19 | 4 | const suits = ["♠", "♥", "♦", "♣"]; |
20 | 5 |
|
21 | | - for (const [rank, value] of Object.entries(expectedValues)) { |
| 6 | + for (let rank = 2; rank <= 10; rank += 1) { |
22 | 7 | for (const suit of suits) { |
23 | | - expect(getCardValue(`${rank}${suit}`)).toEqual(value); |
| 8 | + expect(getCardValue(`${rank}${suit}`)).toEqual(rank); |
24 | 9 | } |
25 | 10 | } |
26 | 11 | }); |
27 | 12 |
|
| 13 | +test("Returns 10 for face cards", () => { |
| 14 | + const suits = ["♠", "♥", "♦", "♣"]; |
| 15 | + |
| 16 | + for (const rank of ["J", "Q", "K"]) { |
| 17 | + for (const suit of suits) { |
| 18 | + expect(getCardValue(`${rank}${suit}`)).toEqual(10); |
| 19 | + } |
| 20 | + } |
| 21 | +}); |
| 22 | + |
| 23 | +test("Returns 11 for aces", () => { |
| 24 | + for (const suit of ["♠", "♥", "♦", "♣"]) { |
| 25 | + expect(getCardValue(`A${suit}`)).toEqual(11); |
| 26 | + } |
| 27 | +}); |
| 28 | + |
28 | 29 | test("Throws an error for invalid card formats", () => { |
29 | 30 | const invalidCards = [ |
30 | 31 | "A", |
|
0 commit comments