Skip to content

Commit 4472fa2

Browse files
committed
fix errors
1 parent 9de9db0 commit 4472fa2

3 files changed

Lines changed: 38 additions & 42 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ function isProperFraction(numerator, denominator) {
1515
if (denominator <= 0) {
1616
return false;
1717
}
18-
if (numerator < 0) {
19-
return false;
20-
}
2118
return numerator < denominator;
2219
}
2320

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

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function getCardValue(card) {
2727
// Get the suit (last character) and rank (everything before it)
2828
const suit = card.slice(-1);
2929
const rank = card.slice(0, -1);
30+
console.log(suit, rank);
3031

3132
// Check that the suit is valid
3233
if (!validSuits.includes(suit)) {
@@ -56,24 +57,6 @@ function getCardValue(card) {
5657
}
5758

5859
throw new Error("Invalid card");
59-
60-
{
61-
return Number(rank);
62-
}
63-
64-
// Invalid rank
65-
throw new Error("Invalid card");
66-
getCardValue("1♠");
67-
getCardValue("11♣");
68-
getCardValue("0♦");
69-
getCardValue("B♥");
70-
getCardValue("X♠");
71-
72-
//invalid suit
73-
getCardValue("AX");
74-
getCardValue("5*");
75-
getCardValue("10H");
76-
getCardValue("QS");
7760
}
7861

7962
// The line below allows us to load the getCardValue function into tests in other files.
@@ -88,19 +71,32 @@ function assertEquals(actualOutput, targetOutput) {
8871
);
8972
}
9073

91-
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
92-
// Examples:
93-
assertEquals(getCardValue("9♠"), 9);
94-
95-
// Handling invalid cards
96-
try {
97-
getCardValue("invalid");
98-
99-
// This line will not be reached if an error is thrown as expected
100-
console.error("Error was not thrown for invalid card 😢");
101-
} catch (e) {
102-
console.log("Error thrown for invalid card 🎉");
103-
}
104-
105-
// What other invalid card cases can you think of?
106-
//invalid rank
74+
// // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
75+
// // Examples:
76+
// assertEquals(getCardValue("9♠"), 9);
77+
78+
// // Handling invalid cards
79+
// try {
80+
// getCardValue("invalid");
81+
82+
// // This line will not be reached if an error is thrown as expected
83+
// console.error("Error was not thrown for invalid card 😢");
84+
// } catch (e) {
85+
// console.log("Error thrown for invalid card 🎉");
86+
// }
87+
88+
// // What other invalid card cases can you think of?
89+
// //invalid rank
90+
// getCardValue("1♠");
91+
// getCardValue("11♣");
92+
// getCardValue("0♦");
93+
// getCardValue("B♥");
94+
// getCardValue("X♠");
95+
96+
// //invalid suit
97+
// getCardValue("AX");
98+
// getCardValue("5*");
99+
// getCardValue("10H");
100+
// getCardValue("QS");
101+
102+
getCardValue("1♠");

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ test("should return 10 for face cards", () => {
2323
});
2424

2525
// Case 4: Invalid cards
26-
test("should return 0 for invalid cards", () => {
27-
expect(getCardValue("1♠")).toEqual(0);
28-
expect(getCardValue("11♣")).toEqual(0);
29-
expect(getCardValue("X♦")).toEqual(0);
30-
expect(getCardValue("")).toEqual(0);
26+
test("should return error for invalid cards", () => {
27+
expect(() => {
28+
getCardValue("1♠");
29+
}).toThrow("Invalid card");
30+
// expect(getCardValue("1♠")).toEqual(0);
31+
// expect(getCardValue("11♣")).toEqual(0);
32+
// expect(getCardValue("X♦")).toEqual(0);
33+
// expect(getCardValue("")).toEqual(0);
3134
});
3235

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

0 commit comments

Comments
 (0)