Skip to content

Commit a95ca14

Browse files
committed
Address the issues from the pull request comments
1 parent c98b477 commit a95ca14

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
12-
return true;
13-
} else {
11+
if (denominator === 0) {
1412
return false;
1513
}
14+
15+
return Math.abs(numerator) < Math.abs(denominator);
1616
}
1717

1818
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -59,3 +59,9 @@ assertEquals(equalFraction, false);
5959

6060
// Stretch:
6161
// What other scenarios could you test for?
62+
63+
const divideByZero = isProperFraction(3, 0);
64+
assertEquals(divideByZero, false);
65+
66+
const zeroNumerator = isProperFraction(0, 3);
67+
assertEquals(zeroNumerator, true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
const rank = card[0];
11+
const rank = card.slice(0, -1);
1212

1313
if (rank === "A") {
1414
return 11;
1515
} else if (["J", "Q", "K"].includes(rank)) {
1616
return 10;
17-
} else if (rank >= 2 || rank <= 10) {
17+
} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 10) {
1818
return Number(rank);
1919
} else {
2020
return "Invalid card rank.";

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ test("should return true for a proper fraction", () => {
77
});
88

99
// Case 2: Identify Improper Fractions:
10-
test("should return false for an import fraction", () => {
10+
test("should return false for an improper fraction", () => {
1111
expect(isProperFraction(3, 2)).toEqual(false);
1212
});
1313

14+
test("should return false for an improper fraction", () => {
15+
expect(isProperFraction(-5, 3)).toEqual(false);
16+
});
17+
1418
// Case 3: Identify Negative Fractions:
1519
test("should return true for a negative fraction", () => {
1620
expect(isProperFraction(-4, 7)).toEqual(true);
1721
});
1822

23+
test("should return true for a negative fraction", () => {
24+
expect(isProperFraction(4, -7)).toEqual(true);
25+
});
26+
1927
// Case 4: Identify Equal Numerator and Denominator:
2028
test("should return false for a fraction whose numerator and denominator are the same", () => {
2129
expect(isProperFraction(3, 3)).toEqual(false);

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ test("should return 11 for Ace of Spades", () => {
88
});
99

1010
// Case 2: Handle Number Cards (2-10):
11-
test("should return 5 for a number card", () => {
12-
const fiveofHearts = getCardValue("5♥");
13-
expect(fiveofHearts).toEqual(5);
14-
});
11+
for (let i = 2; i <= 10; i++) {
12+
test(`should return ${i} for a number card ${i}♥`, () => {
13+
const card = getCardValue(`${i}♥`);
14+
expect(card).toEqual(i);
15+
});
16+
}
1517

1618
// Case 3: Handle Face Cards (J, Q, K):
17-
test("should return 10 for a face card", () => {
18-
const jackOfDiamonds = getCardValue("J♢");
19-
expect(jackOfDiamonds).toEqual(10);
20-
});
19+
const faceCards = ["J", "Q", "K"];
20+
21+
for (let faceCard of faceCards) {
22+
test(`should return 10 for a card card ${faceCard}♢`, () => {
23+
const card = getCardValue(`${faceCard}♢`);
24+
expect(card).toEqual(10);
25+
});
26+
}
2127

2228
// Case 4: Handle Ace (A):
2329
test("should return 11 for an Ace", () => {
24-
const ace = getCardValue("A");
30+
const ace = getCardValue("A");
2531
expect(ace).toEqual(11);
2632
});
2733

0 commit comments

Comments
 (0)