Skip to content

Commit f752ead

Browse files
committed
updates for sprint 3 3-Get-card-valuse
1 parent dbdc848 commit f752ead

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ assertEquals(getCardValue("J♦"), 10);
6363
assertEquals(getCardValue("Q♣"), 10);
6464
assertEquals(getCardValue("K♦"), 10);
6565
assertEquals(getCardValue("10♥"), 10);
66-
assertEquals(getCardValue("11♠"), "invalid"); // This should throw an error
67-
assertEquals(getCardValue("A"), "invalid"); // This should throw an error
68-
assertEquals(getCardValue("2X"), "invalid"); // This should throw an error
6966

67+
// Test invalid cards - these should throw errors
68+
function testInvalidCard(card) {
69+
try {
70+
getCardValue(card);
71+
console.error(`Error was not thrown for invalid card: ${card}`);
72+
} catch (e) {
73+
console.log(`✓ Correctly threw error for: ${card}`);
74+
}
75+
}
7076

71-
72-
// Handling invalid cards
73-
try {
74-
getCardValue("invalid");
75-
76-
// This line will not be reached if an error is thrown as expected
77-
console.error("Error was not thrown for invalid card");
78-
} catch (e) {}
79-
80-
// What other invalid card cases can you think of?
81-
assertEquals(getCardValue(""), "invalid"); // This should throw an error
82-
assertEquals(getCardValue("A♠♠"), "invalid"); // This should throw an error
83-
assertEquals(getCardValue("1♠"), "invalid"); // This should throw an error
84-
assertEquals(getCardValue("B♠"), "invalid"); // This should throw an error
85-
assertEquals(getCardValue("A♠A"), "invalid"); // This should throw an error
77+
testInvalidCard("11♠"); // Invalid rank
78+
testInvalidCard("A"); // Missing suit
79+
testInvalidCard("2X"); // Invalid suit
80+
testInvalidCard("invalid"); // Completely invalid
81+
testInvalidCard(""); // Empty string
82+
testInvalidCard("A♠♠"); // Extra character
83+
testInvalidCard("1♠"); // Invalid rank (1 instead of A)
84+
testInvalidCard("B♠"); // Invalid rank
85+
testInvalidCard("A♠A"); // Invalid format

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ test(`Should throw an error when given an invalid card`, () => {
2323
expect(() => getCardValue("11♠")).toThrow("Invalid card: Invalid rank");
2424
expect(() => getCardValue("A")).toThrow("Invalid card: Invalid suit");
2525
expect(() => getCardValue("2X")).toThrow("Invalid card: Invalid suit");
26-
}
26+
});
2727
// To learn how to test whether a function throws an error as expected in Jest,
2828
// please refer to the Jest documentation:
2929
// https://jestjs.io/docs/expect#tothrowerror
30-

0 commit comments

Comments
 (0)