Skip to content

Commit f57a756

Browse files
Fixing error base on PR review
1 parent 1ec84d6 commit f57a756

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,25 @@ function getCardValue(card) {
3939
"K",
4040
];
4141
const cardSuits = ["♠", "♥", "♦", "♣"];
42+
let rank = card.slice(0,-1);
43+
let suit = card.slice(-1);
4244
if (
4345
typeof card !== "string" ||
44-
!cardRanks.includes(card.slice(0,-1)) ||
45-
!cardSuits.includes(card.slice(-1))
46+
!cardRanks.includes(rank) ||
47+
!cardSuits.includes(suit)
4648
) {
4749
throw new Error("Invalid card");
4850
}
4951

50-
switch (card.slice(0, -1)) {
52+
switch (rank) {
5153
case "A":
5254
return 11;
5355
case "J":
5456
case "Q":
5557
case "K":
5658
return 10;
5759
default:
58-
return Number(card.slice(0, -1));
60+
return Number(rank);
5961
}
6062
}
6163

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ test(`should return "Reflex angle" when ( 180 < angle < 360)`, () => {
3434
expect(getAngleType(359)).toEqual("Reflex angle");
3535
});
3636
// Case 6: Invalid angles
37-
test(`should return "Invalid angle" when ( 180 < angle < 360)`, () => {
37+
test(`should return "Invalid angle" when ( 0 < angle && angle > 360)`, () => {
3838
expect(getAngleType(-1)).toEqual("Invalid angle");
3939
expect(getAngleType(-10)).toEqual("Invalid angle");
4040
expect(getAngleType(361)).toEqual("Invalid angle");
41+
expect(getAngleType(0)).toEqual("Invalid angle");
42+
expect(getAngleType(360)).toEqual("Invalid angle");
4143
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ test(`should return false when denominator is zero`, () => {
1111
test(`should return false when numerator is zero`, () => {
1212
expect(isProperFraction(0, 1)).toEqual(false);
1313
});
14-
test(`should return false when numerator is negative`, () => {
14+
test(`should return false when numerator < denominator `, () => {
1515
expect(isProperFraction(-1, 2)).toEqual(false);
1616
});
17-
test(`should return false when denominator is negative`, () => {
17+
test(`should return false when denominator < numerator`, () => {
1818
expect(isProperFraction(1, -2)).toEqual(false);
1919
});
20-
test(`should return false when denominator is infinity`, () => {
20+
test(`should return false when denominator is bigInt`, () => {
2121
expect(isProperFraction(1, 23443243n)).toEqual(true);
2222
});
2323
test(`should return false when numerator is infinity`, () => {

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,31 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14-
test("Should return 2 for '2♠'", () => {
15-
expect(getCardValue("2♠")).toEqual(2);
16-
});
14+
test("Should return the value of the card in interval of [2,10]", () => {
15+
expect(getCardValue("2♠")).toEqual(2);
1716

18-
test("Should return 5 for '5♥'", () => {
19-
expect(getCardValue("5♥")).toEqual(5);
20-
});
17+
expect(getCardValue("5♥")).toEqual(5);
2118

22-
test("Should return 9 for '9♦'", () => {
23-
expect(getCardValue("9♦")).toEqual(9);
24-
});
19+
expect(getCardValue("9♦")).toEqual(9);
2520

26-
test("Should return 10 for '10♣'", () => {
27-
expect(getCardValue("10♣")).toEqual(10);
28-
});
21+
expect(getCardValue("10♣")).toEqual(10);
22+
});
2923

3024
// Face Cards (J, Q, K)
3125
test("Should return 10 for 'J♠'", () => {
32-
expect(getCardValue("J♠")).toEqual(10);
33-
});
26+
expect(getCardValue("J♠")).toEqual(10);
27+
});
3428

35-
test("Should return 10 for 'Q♥'", () => {
36-
expect(getCardValue("Q♥")).toEqual(10);
37-
});
29+
test("Should return 10 for 'Q♥'", () => {
30+
expect(getCardValue("Q♥")).toEqual(10);
31+
});
3832

39-
test("Should return 10 for 'K♦'", () => {
40-
expect(getCardValue("K♦")).toEqual(10);
41-
});
33+
test("Should return 10 for 'K♦'", () => {
34+
expect(getCardValue("K♦")).toEqual(10);
35+
});
4236

4337
// Invalid Cards
44-
test("Should throw error for missing suit (e.g., 'A')", () => {
38+
test("Should throw error for missing suit (e.g., 'A')", () => {
4539
expect(() => getCardValue("A")).toThrow("Invalid card");
4640
});
4741

@@ -57,8 +51,6 @@ test("Should throw error for undefined", () => {
5751
expect(() => getCardValue(undefined)).toThrow("Invalid card");
5852
});
5953

60-
6154
// To learn how to test whether a function throws an error as expected in Jest,
6255
// please refer to the Jest documentation:
6356
// https://jestjs.io/docs/expect#tothrowerror
64-

0 commit comments

Comments
 (0)