Skip to content

Commit a8246a5

Browse files
committed
I have done all required task for sprint 3
1 parent 5a0eb94 commit a8246a5

File tree

10 files changed

+342
-27
lines changed

10 files changed

+342
-27
lines changed

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

Lines changed: 176 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
// Check for invalid angles (outside 0-360 range or negative)
20+
if (angle <= 0 || angle >= 360) {
21+
return "Invalid angle";
22+
}
23+
24+
// Check for acute angle (0 < angle < 90)
25+
if (angle < 90) {
26+
return "Acute angle";
27+
}
28+
29+
// Check for right angle (exactly 90)
30+
if (angle === 90) {
31+
return "Right angle";
32+
}
33+
34+
// Check for obtuse angle (90 < angle < 180)
35+
if (angle < 180) {
36+
return "Obtuse angle";
37+
}
38+
39+
// Check for straight angle (exactly 180)
40+
if (angle === 180) {
41+
return "Straight angle";
42+
}
43+
44+
// Check for reflex angle (180 < angle < 360)
45+
if (angle < 360) {
46+
return "Reflex angle";
47+
}
48+
49+
// This should not be reached due to the first check, but included for completeness
50+
return "Invalid angle";
1951
}
2052

2153
// The line below allows us to load the getAngleType function into tests in other files.
@@ -29,9 +61,152 @@ function assertEquals(actualOutput, targetOutput) {
2961
actualOutput === targetOutput,
3062
`Expected ${actualOutput} to equal ${targetOutput}`
3163
);
32-
}
64+
}
3365

3466
// TODO: Write tests to cover all cases, including boundary and invalid cases.
3567
// Example: Identify Right Angles
68+
69+
// ============================================================
70+
// ACUTE ANGLE TESTS (0 < angle < 90)
71+
// ============================================================
72+
console.log("--- Acute Angle Tests (0° < angle < 90°) ---");
73+
74+
const acute1 = getAngleType(1);
75+
assertEquals(acute1, "Acute angle");
76+
console.log(" Test: 1° is Acute angle");
77+
78+
const acute2 = getAngleType(45);
79+
assertEquals(acute2, "Acute angle");
80+
console.log(" Test: 45° is Acute angle");
81+
82+
const acute3 = getAngleType(60);
83+
assertEquals(acute3, "Acute angle");
84+
console.log("Test: 60° is Acute angle");
85+
86+
const acute4 = getAngleType(89);
87+
assertEquals(acute4, "Acute angle");
88+
console.log(" Test: 89° is Acute angle (boundary - just below 90°)");
89+
90+
const acute5 = getAngleType(0.5);
91+
assertEquals(acute5, "Acute angle");
92+
console.log(" Test: 0.5° is Acute angle (decimal)");
93+
94+
// ============================================================
95+
// RIGHT ANGLE TEST (exactly 90)
96+
// ============================================================
97+
console.log("\n--- Right Angle Test (exactly 90°) ---");
98+
3699
const right = getAngleType(90);
37100
assertEquals(right, "Right angle");
101+
console.log(" Test: 90° is Right angle");
102+
103+
// ============================================================
104+
// OBTUSE ANGLE TESTS (90 < angle < 180)
105+
// ============================================================
106+
console.log("\n--- Obtuse Angle Tests (90° < angle < 180°) ---");
107+
108+
const obtuse1 = getAngleType(91);
109+
assertEquals(obtuse1, "Obtuse angle");
110+
console.log(" Test: 91° is Obtuse angle (boundary - just above 90°)");
111+
112+
const obtuse2 = getAngleType(120);
113+
assertEquals(obtuse2, "Obtuse angle");
114+
console.log(" Test: 120° is Obtuse angle");
115+
116+
const obtuse3 = getAngleType(135);
117+
assertEquals(obtuse3, "Obtuse angle");
118+
console.log(" Test: 135° is Obtuse angle");
119+
120+
const obtuse4 = getAngleType(179);
121+
assertEquals(obtuse4, "Obtuse angle");
122+
console.log(" Test: 179° is Obtuse angle (boundary - just below 180°)");
123+
124+
const obtuse5 = getAngleType(150.5);
125+
assertEquals(obtuse5, "Obtuse angle");
126+
console.log(" Test: 150.5° is Obtuse angle (decimal)");
127+
128+
// ============================================================
129+
// STRAIGHT ANGLE TEST (exactly 180)
130+
// ============================================================
131+
console.log("\n--- Straight Angle Test (exactly 180°) ---");
132+
133+
const straight = getAngleType(180);
134+
assertEquals(straight, "Straight angle");
135+
console.log(" Test: 180° is Straight angle");
136+
137+
// ============================================================
138+
// REFLEX ANGLE TESTS (180 < angle < 360)
139+
// ============================================================
140+
console.log("\n--- Reflex Angle Tests (180° < angle < 360°) ---");
141+
142+
const reflex1 = getAngleType(181);
143+
assertEquals(reflex1, "Reflex angle");
144+
console.log(" Test: 181° is Reflex angle (boundary - just above 180°)");
145+
146+
const reflex2 = getAngleType(200);
147+
assertEquals(reflex2, "Reflex angle");
148+
console.log(" Test: 200° is Reflex angle");
149+
150+
const reflex3 = getAngleType(270);
151+
assertEquals(reflex3, "Reflex angle");
152+
console.log(" Test: 270° is Reflex angle");
153+
154+
const reflex4 = getAngleType(300);
155+
assertEquals(reflex4, "Reflex angle");
156+
console.log(" Test: 300° is Reflex angle");
157+
158+
const reflex5 = getAngleType(359);
159+
assertEquals(reflex5, "Reflex angle");
160+
console.log(" Test: 359° is Reflex angle (boundary - just below 360°)");
161+
162+
const reflex6 = getAngleType(225.7);
163+
assertEquals(reflex6, "Reflex angle");
164+
console.log(" Test: 225.7° is Reflex angle (decimal)");
165+
166+
// ============================================================
167+
// INVALID ANGLE TESTS
168+
// ============================================================
169+
console.log("\n--- Invalid Angle Tests ---");
170+
171+
// Zero
172+
const invalid1 = getAngleType(0);
173+
assertEquals(invalid1, "Invalid angle");
174+
console.log(" Test: 0° is Invalid angle");
175+
176+
// Negative angles
177+
const invalid2 = getAngleType(-1);
178+
assertEquals(invalid2, "Invalid angle");
179+
console.log(" Test: -1° is Invalid angle");
180+
181+
const invalid3 = getAngleType(-45);
182+
assertEquals(invalid3, "Invalid angle");
183+
console.log(" Test: -45° is Invalid angle");
184+
185+
const invalid4 = getAngleType(-90);
186+
assertEquals(invalid4, "Invalid angle");
187+
console.log(" Test: -90° is Invalid angle");
188+
189+
const invalid5 = getAngleType(-180);
190+
assertEquals(invalid5, "Invalid angle");
191+
console.log(" Test: -180° is Invalid angle");
192+
193+
// 360 and above
194+
const invalid6 = getAngleType(360);
195+
assertEquals(invalid6, "Invalid angle");
196+
console.log(" Test: 360° is Invalid angle (boundary)");
197+
198+
const invalid7 = getAngleType(361);
199+
assertEquals(invalid7, "Invalid angle");
200+
console.log(" Test: 361° is Invalid angle");
201+
202+
const invalid8 = getAngleType(400);
203+
assertEquals(invalid8, "Invalid angle");
204+
console.log(" Test: 400° is Invalid angle");
205+
206+
const invalid9 = getAngleType(720);
207+
assertEquals(invalid9, "Invalid angle");
208+
console.log(" Test: 720° is Invalid angle (full rotation)");
209+
210+
const invalid10 = getAngleType(1000);
211+
assertEquals(invalid10, "Invalid angle");
212+
console.log(" Test: 1000° is Invalid angle");

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
// Denominator cannot be zero
16+
if (denominator === 0) {
17+
return false;
18+
}
19+
20+
return Math.abs(numerator) < Math.abs(denominator);
1521
}
1622

23+
module.exports = isProperFraction;
24+
25+
1726
// The line below allows us to load the isProperFraction function into tests in other files.
1827
// This will be useful in the "rewrite tests with jest" step.
1928
module.exports = isProperFraction;
@@ -31,3 +40,28 @@ function assertEquals(actualOutput, targetOutput) {
3140

3241
// Example: 1/2 is a proper fraction
3342
assertEquals(isProperFraction(1, 2), true);
43+
44+
// 2. Improper fraction
45+
assertEquals(isProperFraction(3, 2), false);
46+
47+
// 3. Equal numerator & denominator
48+
assertEquals(isProperFraction(2, 2), false);
49+
50+
// 4. Negative numerator
51+
assertEquals(isProperFraction(-1, 2), true);
52+
53+
// 5. Negative denominator
54+
assertEquals(isProperFraction(1, -2), true);
55+
56+
// 6. Both negative
57+
assertEquals(isProperFraction(-1, -2), true);
58+
59+
// 7. Zero numerator
60+
assertEquals(isProperFraction(0, 5), true);
61+
62+
// 8. Zero denominator (invalid fraction)
63+
assertEquals(isProperFraction(5, 0), false);
64+
65+
console.log("All tests executed");
66+
67+

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,42 @@ try {
5050
} catch (e) {}
5151

5252
// What other invalid card cases can you think of?
53+
// Invalid cards
54+
55+
// Invalid string
56+
try {
57+
getCardValue("invalid");
58+
console.error("Error not thrown for invalid string");
59+
} catch (e) {}
60+
61+
// Invalid suit
62+
try {
63+
getCardValue("A?");
64+
console.error("Error not thrown for invalid suit");
65+
} catch (e) {}
66+
67+
// Invalid rank
68+
try {
69+
getCardValue("1♠");
70+
console.error("Error not thrown for invalid rank");
71+
} catch (e) {}
72+
73+
// Missing suit
74+
try {
75+
getCardValue("A");
76+
console.error("Error not thrown for missing suit");
77+
} catch (e) {}
78+
79+
// Empty string
80+
try {
81+
getCardValue("");
82+
console.error("Error not thrown for empty string");
83+
} catch (e) {}
84+
85+
// Not a string
86+
try {
87+
getCardValue(123);
88+
console.error("Error not thrown for non-string input");
89+
} catch (e) {}
90+
91+
console.log("All tests executed");

Sprint-3/2-practice-tdd/count.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
1+
2+
function countChar(str, char) {
3+
let count = 0;
4+
5+
for (let i = 0; i < str.length; i++) {
6+
if (str[i] === char) {
7+
count++;
8+
}
9+
}
10+
11+
return count;
312
}
413

514
module.exports = countChar;

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// implement a function countChar that counts the number of times a character occurs in a string
2+
23
const countChar = require("./count");
4+
5+
test("should count multiple occurrences of a character", () => {
6+
expect(countChar("aaaaa", "a")).toEqual(5);
7+
});
8+
9+
test("should return 0 when character is not found", () => {
10+
expect(countChar("hello", "z")).toEqual(0);
11+
});
12+
313
// Given a string `str` and a single character `char` to search for,
414
// When the countChar function is called with these inputs,
515
// Then it should:
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
const lastTwoDigits = num % 100;
3+
const lastDigit = num % 10;
4+
5+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
6+
return `${num}th`;
7+
}
8+
9+
if (lastDigit === 1) return `${num}st`;
10+
if (lastDigit === 2) return `${num}nd`;
11+
if (lastDigit === 3) return `${num}rd`;
12+
13+
return `${num}th`;
314
}
415

516
module.exports = getOrdinalNumber;

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Find the instances of unreachable and redundant code - remove them!
2-
// The sayHello function should continue to work for any reasonable input it's given.
32

4-
let testName = "Jerry";
5-
const greeting = "hello";
3+
// The sayHello function should continue to work for any reasonable input it's given.
64

75
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
96
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
117
}
128

9+
let testName = "Jerry";
10+
const greeting = "hello";
11+
1312
testName = "Aman";
1413

1514
const greetingMessage = sayHello(greeting, testName);

Sprint-3/3-dead-code/exercise-2.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
33

44
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5-
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
6-
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
75

8-
function logPets(petsArr) {
9-
petsArr.forEach((pet) => console.log(pet));
10-
}
6+
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
117

128
function countAndCapitalisePets(petsArr) {
139
const petCount = {};
1410

1511
petsArr.forEach((pet) => {
1612
const capitalisedPet = pet.toUpperCase();
13+
1714
if (petCount[capitalisedPet]) {
1815
petCount[capitalisedPet] += 1;
1916
} else {
2017
petCount[capitalisedPet] = 1;
2118
}
2219
});
20+
2321
return petCount;
2422
}
2523

2624
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
2725

28-
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
26+
console.log(countedPetsStartingWithH);
27+
// { 'HAMSTER': 3, 'HORSE': 1 }

0 commit comments

Comments
 (0)