Skip to content

Commit 47d5d46

Browse files
committed
the errors mentioned are fixed.
1 parent fed3a0c commit 47d5d46

File tree

12 files changed

+221
-15
lines changed

12 files changed

+221
-15
lines changed

Sprint-3/1-key-implement/1-get-angle-type.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
// Then, write the next test! :) Go through this process until all the cases are implemented
99

1010
function getAngleType(angle) {
11+
if (angle === undefined || isNaN(angle)) {
12+
return "Invalid angle: Please provide a valid number";
13+
}
14+
15+
if (angle < 0 || angle > 360) {
16+
return "Invalid angle: Angle must be between 0 and 360 degrees";
17+
}
18+
19+
if (angle === 360 || angle === 0) return "Full rotation";
20+
1121
if (angle === 90) return "Right angle";
1222
if (angle < 90) return "Acute angle";
1323
if (angle > 90 && angle < 180) return "Obtuse angle";
1424
if (angle === 180) return "Straight angle";
1525
if (angle > 180 && angle < 360) return "Reflex angle";
16-
// read to the end, complete line 36, then pass your test here
1726
}
1827

1928
// we're going to use this helper function to make our assertions easier to read
@@ -60,4 +69,26 @@ assertEquals(straight, "Straight angle");
6069
// Then the function should return "Reflex angle"
6170
// ====> write your test here, and then add a line to pass the test in the function above
6271
const reflex = getAngleType(270);
63-
assertEquals(reflex, "Reflex angle");
72+
assertEquals(reflex, "Reflex angle");
73+
74+
// Case 6: Identify Full Rotation:
75+
// When the angle is exactly 360 degrees or 0 degrees,
76+
// Then the function should return "Full rotation"
77+
const fullRotation = getAngleType(360);
78+
assertEquals(fullRotation, "Full rotation");
79+
const zeroAngle = getAngleType(0);
80+
assertEquals(zeroAngle, "Full rotation");
81+
82+
// Case 7: Handle missing input:
83+
// When no angle is provided,
84+
// Then the function should return an error message
85+
const noAngle = getAngleType();
86+
assertEquals(noAngle, "Invalid angle: Please provide a valid number");
87+
88+
// Case 8: Handle invalid angle values:
89+
// When an angle outside the valid range (0-360 degrees) is provided,
90+
// Then the function should return an error message
91+
const tooBig = getAngleType(361);
92+
assertEquals(tooBig, "Invalid angle: Angle must be between 0 and 360 degrees");
93+
const negative = getAngleType(-10);
94+
assertEquals(negative, "Invalid angle: Angle must be between 0 and 360 degrees");

Sprint-3/1-key-implement/2-is-proper-fraction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function isProperFraction(numerator, denominator) {
1919
function assertEquals(actualOutput, targetOutput) {
2020
console.assert(
2121
actualOutput === targetOutput,
22-
Expected ${actualOutput} to equal ${targetOutput}
22+
`Expected ${actualOutput} to equal ${targetOutput}`
2323
);
2424
}
2525

Sprint-3/1-key-implement/3-get-card-value.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@
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+
if (!card || card.length < 2) {
12+
throw new Error("Invalid card rank.");
13+
}
14+
1115
const rank = card.slice(0, -1);
16+
1217
if (rank === "A") return 11;
1318
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
14-
if (!isNaN(rank)) return Number(rank);
19+
20+
if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9 && rank.length === 1) {
21+
return Number(rank);
22+
}
23+
1524
throw new Error("Invalid card rank.");
1625
}
1726

@@ -70,3 +79,24 @@ try {
7079
} catch (e) {
7180
assertEquals(e.message, "Invalid card rank.");
7281
}
82+
83+
try {
84+
const oddValue = getCardValue("345♠");
85+
console.error("Error was expected but not thrown for '345♠'");
86+
} catch (e) {
87+
assertEquals(e.message, "Invalid card rank.");
88+
}
89+
90+
try {
91+
const onlySuit = getCardValue("♠");
92+
console.error("Error was expected but not thrown for '♠'");
93+
} catch (e) {
94+
assertEquals(e.message, "Invalid card rank.");
95+
}
96+
97+
try {
98+
const oneHundred = getCardValue("100♠");
99+
console.error("Error was expected but not thrown for '100♠'");
100+
} catch (e) {
101+
assertEquals(e.message, "Invalid card rank.");
102+
}

Sprint-3/2-mandatory-rewrite/1-get-angle-type.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
function getAngleType(angle) {
2+
if (angle === undefined || isNaN(angle)) {
3+
return "Invalid angle: Please provide a valid number";
4+
}
5+
6+
if (angle < 0 || angle > 360) {
7+
return "Invalid angle: Angle must be between 0 and 360 degrees";
8+
}
9+
10+
if (angle === 360 || angle === 0) return "Full rotation";
211
if (angle === 90) return "Right angle";
312
if (angle < 90) return "Acute angle";
413
if (angle > 90 && angle < 180) return "Obtuse angle";
514
if (angle === 180) return "Straight angle";
615
if (angle > 180 && angle < 360) return "Reflex angle";
716
}
817

9-
}
10-
1118

1219

1320

Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,20 @@ test("should identify straight angle (180°)", () => {
2525
expect(getAngleType(180)).toEqual("Straight angle");
2626
});
2727

28-
/
28+
test("should identify reflex angles (greater than 180° and less than 360°)", () => {
29+
expect(getAngleType(270)).toEqual("Reflex angle");
30+
});
31+
32+
test("should identify full rotation (0° or 360°)", () => {
33+
expect(getAngleType(360)).toEqual("Full rotation");
34+
expect(getAngleType(0)).toEqual("Full rotation");
35+
});
36+
37+
test("should handle undefined angle value", () => {
38+
expect(getAngleType()).toEqual("Invalid angle: Please provide a valid number");
39+
});
40+
41+
test("should handle angle values outside the valid range", () => {
42+
expect(getAngleType(361)).toEqual("Invalid angle: Angle must be between 0 and 360 degrees");
43+
expect(getAngleType(-10)).toEqual("Invalid angle: Angle must be between 0 and 360 degrees");
44+
});

Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
function isProperFraction(numerator, denominator) {
2-
if (numerator < denominator) return true;
3-
// add your completed function from key-implement here
2+
if (denominator === 0) {
3+
return false;
4+
}
5+
46
if (Math.abs(numerator) < Math.abs(denominator)) {
57
return true;
68
} else {

Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ test("should return true for a negative proper fraction", () => {
1818
test("should return false when numerator and denominator are equal", () => {
1919
expect(isProperFraction(3, 3)).toEqual(false);
2020
});
21+
22+
test("should return false when denominator is zero", () => {
23+
expect(isProperFraction(0, 0)).toEqual(false);
24+
expect(isProperFraction(5, 0)).toEqual(false);
25+
});

Sprint-3/2-mandatory-rewrite/3-get-card-value.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
function getCardValue(card) {
2+
if (!card || card.length < 2) {
3+
throw new Error("Invalid card rank.");
4+
}
5+
26
const rank = card.slice(0, -1);
37
if (rank === "A") return 11;
48
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
5-
if (!isNaN(rank)) return Number(rank);
9+
if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) return Number(rank);
610
throw new Error("Invalid card rank.");
711
}
812

Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ test("should throw error for invalid cards", () => {
2626
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank.");
2727
expect(() => getCardValue("1♠")).toThrow("Invalid card rank.");
2828
});
29+
30+
test("should throw error for multi-digit number (other than 10)", () => {
31+
expect(() => getCardValue("345♠")).toThrow("Invalid card rank.");
32+
});
33+
34+
test("should throw error for only suit (no rank)", () => {
35+
expect(() => getCardValue("♠")).toThrow("Invalid card rank.");
36+
});
37+
38+
test("should throw error for numbers out of range", () => {
39+
expect(() => getCardValue("100♠")).toThrow("Invalid card rank.");
40+
});

Sprint-3/3-mandatory-practice/implement/count.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,24 @@ test("should return 0 if character does not occur", () => {
2929
const count = countChar(str, char);
3030
expect(count).toEqual(0);
3131
});
32+
33+
test("should be case sensitive", () => {
34+
const str = "Hello World";
35+
const char = "h";
36+
const count = countChar(str, char);
37+
expect(count).toEqual(0);
38+
39+
const uppercaseCount = countChar(str, "H");
40+
expect(uppercaseCount).toEqual(1);
41+
});
42+
43+
test("should count spaces as characters", () => {
44+
const str = "Hello World";
45+
const char = " ";
46+
const count = countChar(str, char);
47+
expect(count).toEqual(1);
48+
49+
const multiSpaceStr = "Hello World !";
50+
const multiSpaceCount = countChar(multiSpaceStr, " ");
51+
expect(multiSpaceCount).toEqual(4);
52+
});

0 commit comments

Comments
 (0)