Skip to content

Commit cb8fa8a

Browse files
committed
Group card value cases
1 parent 1c0da29 commit cb8fa8a

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

‎implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import { getCardValue } from "../implement/3-get-card-value.js";
22

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", () => {
194
const suits = ["♠", "♥", "♦", "♣"];
205

21-
for (const [rank, value] of Object.entries(expectedValues)) {
6+
for (let rank = 2; rank <= 10; rank += 1) {
227
for (const suit of suits) {
23-
expect(getCardValue(`${rank}${suit}`)).toEqual(value);
8+
expect(getCardValue(`${rank}${suit}`)).toEqual(rank);
249
}
2510
}
2611
});
2712

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+
2829
test("Throws an error for invalid card formats", () => {
2930
const invalidCards = [
3031
"A",

0 commit comments

Comments
 (0)