Skip to content

Commit a0a794f

Browse files
committed
add tests for getCardValue
1 parent 6014eab commit a0a794f

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,42 @@ import test from "node:test";
33

44
import { getCardValue } from "../implement/3-get-card-value.js";
55

6-
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
7-
86
test("Valid single-digit card", () => {
97
assert.equal(getCardValue("9♠"), 9);
108
});
119

1210
test("Arbitrary non-card string", () => {
13-
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
11+
assert.throws(
12+
() => getCardValue("invalid"),
13+
/Expected a number followed by a suit, but got "invalid"/,
14+
"Expected clear error"
15+
);
16+
});
17+
18+
test("Ace returns 11", () => {
19+
assert.equal(getCardValue("A♠"), 11);
20+
assert.equal(getCardValue("A♥"), 11);
21+
});
22+
23+
test("Face cards return 10", () => {
24+
assert.equal(getCardValue("J♠"), 10);
25+
assert.equal(getCardValue("Q♥"), 10);
26+
assert.equal(getCardValue("K♦"), 10);
27+
});
28+
29+
test("Number cards return their value", () => {
30+
assert.equal(getCardValue("2♣"), 2);
31+
assert.equal(getCardValue("5♥"), 5);
32+
assert.equal(getCardValue("7♠"), 7);
33+
assert.equal(getCardValue("10♦"), 10);
1434
});
1535

16-
// TODO: What other invalid card cases can you think of?
36+
test("Invalid cards throw an error", () => {
37+
assert.throws(() => getCardValue("A"));
38+
assert.throws(() => getCardValue("♠"));
39+
assert.throws(() => getCardValue("11♠"));
40+
assert.throws(() => getCardValue("1♠"));
41+
assert.throws(() => getCardValue("hello"));
42+
assert.throws(() => getCardValue(""));
43+
assert.throws(() => getCardValue("A♠♠"));
44+
});

0 commit comments

Comments
 (0)