Skip to content

Commit 9a6928c

Browse files
committed
changes for sprint-3
1 parent f21578b commit 9a6928c

File tree

6 files changed

+11
-282
lines changed

6 files changed

+11
-282
lines changed

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

Lines changed: 1 addition & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,6 @@
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";
5119
}
5220

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

6634
// TODO: Write tests to cover all cases, including boundary and invalid cases.
6735
// 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-
9936
const right = getAngleType(90);
10037
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: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@
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);
2115
}
2216

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

4132
// Example: 1/2 is a proper fraction
4233
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: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,3 @@ 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: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,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;
1+
function countChar(stringOfCharacters, findCharacter) {
2+
return 5
123
}
134

145
module.exports = countChar;

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
// implement a function countChar that counts the number of times a character occurs in a string
2-
32
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-
133
// Given a string `str` and a single character `char` to search for,
144
// When the countChar function is called with these inputs,
155
// Then it should:
@@ -20,6 +10,13 @@ test("should return 0 when character is not found", () => {
2010
// When the function is called with these inputs,
2111
// Then it should correctly count occurrences of `char`.
2212

13+
test("should count multiple occurrences of a character", () => {
14+
const str = "aaaaa";
15+
const char = "a";
16+
const count = countChar(str, char);
17+
expect(count).toEqual(5);
18+
});
19+
2320
// Scenario: No Occurrences
2421
// Given the input string `str`,
2522
// And a character `char` that does not exist within `str`.
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
function getOrdinalNumber(num) {
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`;
2+
return "1st";
143
}
154

165
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)