Skip to content

Commit e0d6ada

Browse files
author
Baba05206
committed
chore: add package.json for Jest test setup in rewrite-tests-with-jest
1 parent 3975e54 commit e0d6ada

File tree

4 files changed

+4113
-11
lines changed

4 files changed

+4113
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
const rank = card.slice(0, -1);
11+
const rank = card.slice(0, -1).toUpperCase(); // extract the rank by removing the last character (suit)
1212

13-
if (rank === "A") {
14-
return 11;
15-
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") {
16-
return 10;
13+
if (rank === "A") { // ace
14+
return 11; // default value for ace
15+
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") { // face cards and 10
16+
return 10; // value for face cards and 10
1717
} else {
18-
const numericRank = parseInt(rank, 10);
19-
20-
if (!isNaN(numericRank) && numericRank >= 2 && numericRank <= 9) {
21-
return numericRank;
18+
const numericRank = parseInt(rank, 10); // convert rank to a number
19+
if (!isNaN(numericRank) && numericRank >= 2 && numericRank <= 9) { // check if it's a valid number card
20+
return numericRank; // return the numeric value
2221
} else {
23-
throw new Error(`Invalid or unrecognized card rank: "${rank}"`);
22+
throw new Error(`Invalid or unrecognized card rank: "${rank}"`); // handle invalid card ranks
2423
}
2524
}
26-
}
25+
}
2726

2827
// The line below allows us to load the getCardValue function into tests in other files.
2928
// This will be useful in the "rewrite tests with jest" step.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ test("should throw an error for invalid card ranks and provide a descriptive mes
5151
expect(() => getCardValue("♣")).toThrow(
5252
'Invalid or unrecognized card rank: ""'
5353
);
54+
/*
55+
// (Optional) Stretch case — outside normal input expectations
56+
// The function isn't required to handle this, but it tests how the function fails gracefully or otherwise.
5457
expect(() => getCardValue("")).toThrow(
5558
'Invalid or unrecognized card rank: ""'
5659
);
60+
*/
5761
});

0 commit comments

Comments
 (0)