Skip to content

Commit 35475f7

Browse files
committed
Edited a rypo withing the , >= instead of =>. and added more and different case tests for the getCardValue function - looped inputs too
1 parent f8f268c commit 35475f7

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getCardValue(card) {
1818

1919
rank = Number(Math.floor(rank));
2020

21-
if ((rank => 2) && (rank <= 10)) {
21+
if ((rank >= 2) && (rank <= 10)) {
2222
return rank;
2323
}
2424
return "Invalid card rank.";

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,31 @@ test("should return 11 for Ace of Spades", () => {
99

1010
// Case 2: Handle Number Cards (2-10):
1111
test("should return the number entered as input", () => {
12-
const numberCards = getCardValue("4♠");
13-
expect(numberCards).toEqual(4);
12+
for (let i = 2; i <= 10; i++) {
13+
expect(getCardValue(`${i}♠`)).toEqual(i);
14+
}
1415
});
1516

1617
// Case 3: Handle Face Cards (J, Q, K):
1718
test("should return 10 for face cards J Q K", () => {
18-
const faceCards = getCardValue("Q♠");
19-
expect(faceCards).toEqual(10);
19+
expect(getCardValue("Q♠")).toEqual(10);
20+
expect(getCardValue("J♠")).toEqual(10);
21+
expect(getCardValue("K♠")).toEqual(10);
2022
});
2123

2224
// Case 4: Handle Ace (A):
23-
test("should return 11 after entering Ace A", () => {
24-
const handleAce = getCardValue("A♠");
25-
expect(handleAce).toEqual(11);
25+
test("should return 11 when entering Ace A", () => {
26+
expect(getCardValue("A♠")).toEqual(11);
27+
expect(getCardValue("A♥")).toEqual(11);
28+
expect(getCardValue("A♦")).toEqual(11);
29+
expect(getCardValue("A♣")).toEqual(11);
2630
});
2731

2832
// Case 5: Handle Invalid Cards:
2933
test(`should return string ("Invalid card rank.") for invalid inputs`, () => {
30-
const invalidCards = getCardValue("HelloWorld!");
31-
expect(invalidCards).toEqual("Invalid card rank.");
34+
expect(getCardValue("HelloWorld!")).toEqual("Invalid card rank.");
35+
expect(getCardValue("♠")).toEqual("Invalid card rank.");
36+
expect(getCardValue("979")).toEqual("Invalid card rank.");
37+
expect(getCardValue("1")).toEqual("Invalid card rank.");
38+
expect(getCardValue([1, 2, 3])).toEqual("Invalid card rank.");
3239
});

0 commit comments

Comments
 (0)