Skip to content

Commit b1a1d5e

Browse files
committed
refactor getCard function and add more test case
1 parent 865cf09 commit b1a1d5e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
if (
26-
typeof card !== "string" ||
27-
card.length < 2 ||
28-
card.length > 3 ||
29-
card.includes(" ")
30-
) {
25+
if (typeof card !== "string") {
3126
throw new Error("Invalid string");
3227
}
3328

@@ -56,10 +51,9 @@ function getCardValue(card) {
5651
return 11;
5752
} else if (rank === "J" || rank === "Q" || rank === "K") {
5853
return 10;
59-
} else if (rank) {
54+
} else {
6055
return Number(rank);
6156
}
62-
throw new Error("Invalid string");
6357
}
6458

6559
// The line below allows us to load the getCardValue function into tests in other files.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ test("should return false when denominator is zero", () => {
1616
expect(isProperFraction(-1, 0)).toEqual(false);
1717
expect(isProperFraction(1, 0)).toEqual(false);
1818
});
19+
20+
test("should return false when denominator and numerator have both the same negative and positive integer", () => {
21+
expect(isProperFraction(-1, 1)).toEqual(false);
22+
expect(isProperFraction(1, -1)).toEqual(false);
23+
});
24+
25+
test(`should return true when denominator is > numerator `, () => {
26+
expect(isProperFraction(1, 2)).toEqual(true);
27+
expect(isProperFraction(1, 10000)).toEqual(true);
28+
29+
expect(isProperFraction(1e2, 1e3)).toEqual(true);
30+
expect(isProperFraction(-1, 2)).toEqual(true);
31+
});
32+
33+
test("should return false when denominator < numerator", () => {
34+
expect(isProperFraction(1e4, 1)).toEqual(false);
35+
expect(isProperFraction(100, 2)).toEqual(false);
36+
});

0 commit comments

Comments
 (0)