Skip to content

Commit 22cc737

Browse files
a-few-more-tests-and-function-conditions-added
1 parent 7cd95ff commit 22cc737

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@
2424
function getCardValue(card) {
2525
const cardNum = card.slice(0, -1)
2626
const cardSuit = card.slice(-1)
27-
if (cardNum === "A" && "♠♥♦♣".includes(cardSuit)) { return 11}
28-
else if (["J", "Q", "K"].includes(cardNum)) { return 10}
29-
else if (Number(cardNum) >= 2 && Number(cardNum) <= 10) {return Number(cardNum)}
27+
if (cardNum === "A" && "♠♥♦♣".includes(cardSuit)) {
28+
return 11
29+
}
30+
else if (["J", "Q", "K"].includes(cardNum) && "♠♥♦♣".includes(cardSuit)) {
31+
return 10
32+
}
33+
else if (Number(cardNum) >= 2 && Number(cardNum) <= 10 && "♠♥♦♣".includes(cardSuit)) {
34+
return Number(cardNum)
35+
}
3036
else throw new Error("Invalid card");
3137
}
3238

@@ -57,24 +63,50 @@ try {
5763

5864
// This line will not be reached if an error is thrown as expected
5965
console.error("Error was not thrown for invalid card");
60-
} catch (e) {}
66+
} catch (e) {
67+
assertEquals(e.message, "Invalid card")
68+
}
6169
try {
6270
getCardValue("♦Q");
6371

6472
// This line will not be reached if an error is thrown as expected
6573
console.error("Error was not thrown for invalid card");
66-
} catch (e) {}
74+
} catch (e) {
75+
assertEquals(e.message, "Invalid card")
76+
}
6777
try {
6878
getCardValue("11♦");
6979

7080
// This line will not be reached if an error is thrown as expected
7181
console.error("Error was not thrown for invalid card");
72-
} catch (e) {}
82+
} catch (e) {
83+
assertEquals(e.message, "Invalid card")
84+
}
7385

7486
try {
7587
getCardValue("AX");
7688

7789
// This line will not be reached if an error is thrown as expected
7890
console.error("Error was not thrown for invalid card");
79-
} catch (e) {}
91+
} catch (e) {
92+
assertEquals(e.message, "Invalid card")
93+
}
94+
95+
try {
96+
getCardValue("KX");
97+
98+
// This line will not be reached if an error is thrown as expected
99+
console.error("Error was not thrown for invalid card");
100+
} catch (e) {
101+
assertEquals(e.message, "Invalid card")
102+
}
103+
104+
try {
105+
getCardValue("5X");
106+
107+
// This line will not be reached if an error is thrown as expected
108+
console.error("Error was not thrown for invalid card");
109+
} catch (e) {
110+
assertEquals(e.message, "Invalid card")
111+
}
80112
// What other invalid card cases can you think of?

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ test(`Should return Error when given an 11♦`, () => {
3232
test(`Should return Error when given an AX`, () => {
3333
expect(function() {getCardValue("AX")}).toThrow("Invalid card");
3434
});
35+
test(`Should return Error when given an KX`, () => {
36+
expect(function() {getCardValue("KX")}).toThrow("Invalid card");
37+
});
38+
test(`Should return Error when given an 5X`, () => {
39+
expect(function() {getCardValue("5X")}).toThrow("Invalid card");
40+
});
3541

3642

3743
// Suggestion: Group the remaining test data into these categories:

0 commit comments

Comments
 (0)