Skip to content

Commit 4ea61d3

Browse files
author
Payman IB
committed
Add tests for getCardValue function to cover number cards, face cards, Ace, and invalid ranks
1 parent 1d68450 commit 4ea61d3

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,32 @@ assertEquals(aceofSpades, 11);
5050
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
5151
const fiveofHearts = getCardValue("5♥");
5252
// ====> write your test here, and then add a line to pass the test in the function above
53-
53+
assertEquals(fiveofHearts, 5);
5454
// Handle Face Cards (J, Q, K):
5555
// Given a card with a rank of "10," "J," "Q," or "K",
5656
// When the function is called with such a card,
5757
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
58+
const tenofDiamonds = getCardValue("10♦");
59+
const jackofClubs = getCardValue("J♣");
60+
const queenofHearts = getCardValue("Q♥");
61+
const kingofSpades = getCardValue("K♠");
5862

63+
assertEquals(tenofDiamonds, 10);
64+
assertEquals(jackofClubs, 10);
65+
assertEquals(queenofHearts, 10);
66+
assertEquals(kingofSpades, 10);
5967
// Handle Ace (A):
6068
// Given a card with a rank of "A",
6169
// When the function is called with an Ace,
6270
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
63-
71+
const aceofDiamonds = getCardValue("A♦");
72+
assertEquals(aceofDiamonds, 11);
6473
// Handle Invalid Cards:
6574
// Given a card with an invalid rank (neither a number nor a recognized face card),
6675
// When the function is called with such a card,
6776
// Then it should throw an error indicating "Invalid card rank."
77+
const invalidCard1 = () => getCardValue("1♠");
78+
assertEquals(invalidCard1 instanceof Function, true);
79+
80+
const invalidCard2 = () => getCardValue("B♥");
81+
assertEquals(invalidCard2 instanceof Function, true);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This statement loads the getCardValue function you wrote in the implement directory.
22
// We will use the same function, but write tests for it using Jest in this file.
3+
// const { test } = require("picomatch");
34
const getCardValue = require("../implement/3-get-card-value");
45

56
test("should return 11 for Ace of Spades", () => {
@@ -8,6 +9,27 @@ test("should return 11 for Ace of Spades", () => {
89
});
910

1011
// Case 2: Handle Number Cards (2-10):
12+
test("should return numeric value for number cards (2-10)", () => {
13+
const fiveofHearts = getCardValue("5♥");
14+
expect(fiveofHearts).toEqual(5);
15+
});
1116
// Case 3: Handle Face Cards (J, Q, K):
17+
test("should return 10 for face cards (J, Q, K) and 10", () => {
18+
expect(getCardValue("10♦")).toEqual(10);
19+
expect(getCardValue("J♣")).toEqual(10);
20+
expect(getCardValue("Q♥")).toEqual(10);
21+
expect(getCardValue("K♠")).toEqual(10);
22+
});
1223
// Case 4: Handle Ace (A):
24+
test("should return 11 for Ace (A)", () => {
25+
expect(getCardValue("A♦")).toEqual(11);
26+
});
1327
// Case 5: Handle Invalid Cards:
28+
test("should throw an error for invalid card rank", () => {
29+
expect(() => {
30+
getCardValue("1♠");
31+
}).toThrow("Invalid card rank.");
32+
expect(() => {
33+
getCardValue("B♥");
34+
}).toThrow("Invalid card rank.");
35+
});

0 commit comments

Comments
 (0)