Skip to content

Commit 254abc7

Browse files
committed
Updated as per PR comments
1 parent f6f394c commit 254abc7

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ function getAngleType(angle) {
3737
else if (angle > 180 && angle < 360) {
3838
return "Reflex angle";
3939
}
40-
41-
// if it is 360 then it is a full rotation
42-
else if (angle === 360) {
43-
return "Full rotation";
44-
}
4540
// everything greater than 360 rand less than 0 return invalid angle
4641
else {
4742
return "Invalid angle";

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,33 @@
2424
function getCardValue(card) {
2525
const suits = ["♠", "♥", "♦", "♣"]; // valid card suits
2626

27-
const suit = card.slice(-1); // gives me the last character
28-
const rank = card.slice(0, -1); // gets beginning character up to (not including) the last character
27+
let suit = "";
28+
let rank = card;
2929

30-
if (!suits.includes(suit)) {
30+
if (card.length > 1) {
31+
suit = card.slice(-1); // gives me the last character and saves it in the suit variable.
32+
rank = card.slice(0, -1); // gets beginning character up to (not including) the last character and saves it in the rank variable.
33+
}
34+
35+
if (suit && !suits.includes(suit)) {
3136
throw new Error("Error invalid card");
3237
}
33-
// TODO: Implement this function
3438

3539
// if card is an ace return 11
36-
if (card === "A") {
40+
if (rank === "A") {
3741
return 11;
3842
}
3943

4044
// if card is face "J", "Q", "K"
41-
else if (card === "J" || card === "Q" || card === "K") {
45+
else if (rank === "J" || rank === "Q" || rank === "K") {
4246
return 10;
4347
}
4448

4549
// if card is a number card and card is bigger than 2 and less than 10 ("2" to "10"), should return its numerical value
46-
else if (Number(card) >= 2 && Number(card) <= 10) {
47-
return Number(card);
48-
} else {
49-
throw new Error("Error invalid card");
50+
else if (Number(rank) >= 2 && Number(rank) <= 10) {
51+
return Number(rank);
5052
}
53+
throw new Error("Error invalid card");
5154
}
5255

5356
// 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/1-get-angle-type.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,11 @@ test(`should return "Reflex angles" when (angle > 180 && < 360)`, () => {
3737
expect(getAngleType(245)).toEqual("Reflex angle");
3838
expect(getAngleType(306)).toEqual("Reflex angle");
3939
});
40-
// Case 6: Full rotation
41-
test("returns full rotation for 360 degrees (angle === 360))", () => {
42-
expect(getAngleType(360)).toBe("Full rotation");
43-
});
44-
// Case 7: Invalid angles
45-
test(`should return "Invalid angles" when (angle >360)`, () => {
40+
// Case 6: Invalid angles
41+
test(`should return "Invalid angles" when (angle is =<0 &&>=360)`, () => {
4642
// Test various invalid angles, including boundary cases
4743
expect(getAngleType(400)).toEqual("Invalid angle");
48-
});
49-
// Case 8: Invalid angles
50-
test(`should return "Invalid angles" when (angle <0)`, () => {
5144
expect(getAngleType(-7)).toBe("Invalid angle");
45+
expect(getAngleType(360)).toBe("Invalid angle");
46+
expect(getAngleType(0)).toBe("Invalid angle");
5247
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test(`should return false when denominator is zero`, () => {
1111

1212
// Case 2: Proper fractions
1313
// the numerator is smaller than the denominator, so the fraction is a proper fraction
14-
test(`should return true when |numerator| < |denominator|`, () => {
14+
test(`should return true when numerator < denominator`, () => {
1515
expect(isProperFraction(6, 7)).toEqual(true);
1616
expect(isProperFraction(2, 4)).toEqual(true);
1717
});
@@ -27,7 +27,7 @@ test("should return false when numerator is bigger than denominator", () => {
2727
// numerator or denominator is negative, but function compares absolute values
2828
test("should return correct result when numerator or denominator is negative", () => {
2929
expect(isProperFraction(-5, 9)).toEqual(true);
30-
expect(isProperFraction(-2, 0)).toEqual(false);
30+
expect(isProperFraction(7, -3)).toEqual(false);
3131
});
3232

3333
// Case 5: Numerator equals denominator fraction equals 1, so it is not proper

0 commit comments

Comments
 (0)