Skip to content

Commit 49049fe

Browse files
committed
write tests for 1-implement-and-rewrite-tests/implement/3-get-card-value.js
1 parent 3780aff commit 49049fe

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const ranks = "A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",");
27+
const suites = "♠,♥,♦,♣".split(",");
28+
const validCards = new Set();
29+
for (const rank of ranks) {
30+
for (const suite of suites) {
31+
validCards.add(rank + suite);
32+
}
33+
}
2634
}
2735

2836
// The line below allows us to load the getCardValue function into tests in other files.
@@ -40,6 +48,12 @@ function assertEquals(actualOutput, targetOutput) {
4048
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4149
// Examples:
4250
assertEquals(getCardValue("9♠"), 9);
51+
assertEquals(getCardValue("A"), 11);
52+
assertEquals(getCardValue("Q"), 10);
53+
assertEquals(getCardValue("5"), 5);
54+
assertEquals(getCardValue(true), "invalid");
55+
assertEquals(getCardValue("A♠"), 11);
56+
// assertEquals(getCardValue("invalid"), 9);
4357

4458
// Handling invalid cards
4559
try {

0 commit comments

Comments
 (0)