Skip to content

Commit e569ea9

Browse files
committed
updated test cases for the function
1 parent cb7b6ef commit e569ea9

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25+
if (Number(card) < 1 || Number(card) > 11) {
26+
throw new Error("Error");
27+
}
2528
const removeSuit = card.slice(0, -1);
2629
if (removeSuit === "A") {
2730
return 11;
28-
} else if (removeSuit === "J" || removeSuit === "Q" ||removeSuit === "K") {
31+
} else if (removeSuit === "J" || removeSuit === "Q" || removeSuit === "K") {
2932
return 10;
3033
} else if (removeSuit > 1 && removeSuit < 11) {
3134
return Number(removeSuit);
3235
} else {
33-
throw new Error("Error")
36+
throw new Error("Error");
3437
}
3538
}
3639

@@ -74,4 +77,3 @@ try {
7477
} catch (e) {
7578
console.log("Error thrown for invalid card 🎉");
7679
}
77-

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Special case: numerator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10+
expect(isProperFraction(-1, 0)).toEqual(false);
11+
expect(isProperFraction(0, 0)).toEqual(false);
1012
});
11-
test(`should return true when denominator is smaller or equal to the numerator`,() =>{
13+
test(`should return true when denominator is smaller or equal to the numerator`, () => {
1214
expect(isProperFraction(2, 4)).toEqual(true);
1315
expect(isProperFraction(3, 3)).toEqual(true);
1416
expect(isProperFraction(5, 10)).toEqual(true);
1517
expect(isProperFraction(2, 2)).toEqual(true);
1618
});
17-
19+
1820
test(`should return false when denominator is bigger than the numerator`, () => {
1921
expect(isProperFraction(12, 4)).toEqual(false);
22+
expect(isProperFraction(2, 1)).toEqual(false);
2023
});
2124

2225
test("should return false when the numerator or denominator is not a positive number", () => {
2326
expect(isProperFraction(5, -2)).toEqual(false);
24-
expect(isProperFraction(-1, 0)).toEqual(false);
27+
expect(isProperFraction(12, -44)).toEqual(false);
2528
});
2629

30+

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ const getCardValue = require("../implement/3-get-card-value");
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
11-
12-
// Case 2:
13-
11+
// Case 2:
1412
test(`should return 10 for face cards"`, () => {
1513
expect(getCardValue("J♥")).toEqual(10);
1614
expect(getCardValue("K♠")).toEqual(10);
@@ -20,10 +18,9 @@ test(`should return 10 for face cards"`, () => {
2018
//Case 3:
2119
test(`should return the numeric value of numbered cards`, () => {
2220
expect(getCardValue("2♠")).toEqual(2);
23-
expect(getCardValue("5")).toEqual(5);
24-
expect(getCardValue("8")).toEqual(8);
21+
expect(getCardValue("5")).toEqual(5);
22+
expect(getCardValue("8")).toEqual(8);
2523
});
26-
2724
// Suggestion: Group the remaining test data into these categories:
2825
// Number Cards (2-10)
2926
// Face Cards (J, Q, K)
@@ -35,5 +32,9 @@ test(`should return the numeric value of numbered cards`, () => {
3532
test(`Should not return any card should throw an error message`, () => {
3633
expect(() => {
3734
getCardValue("QQ♥");
35+
getCardValue("♠♥");
36+
getCardValue("88");
37+
getCardValue("00");
38+
getCardValue("0");
3839
}).toThrow();
3940
});

0 commit comments

Comments
 (0)