Skip to content

Commit 696a379

Browse files
author
Payman IB
committed
Refactor code structure for improved readability and maintainability
1 parent c335f18 commit 696a379

File tree

6 files changed

+9065
-6
lines changed

6 files changed

+9065
-6
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@ function getAngleType(angle) {
1111
if (angle === 90) {
1212
return "Right angle";
1313
}
14-
// Run the tests, work out what Case 2 is testing, and implement the required code here.
15-
// Then keep going for the other cases, one at a time.
14+
15+
if (angle < 90) {
16+
return "Acute angle";
17+
}
18+
19+
if (angle > 90 && angle < 180) {
20+
return "Obtuse angle";
21+
}
22+
23+
if (angle === 180) {
24+
return "Straight angle";
25+
}
26+
27+
if (angle > 180 && angle < 360) {
28+
return "Reflex angle";
29+
}
1630
}
1731

1832
// The line below allows us to load the getAngleType function into tests in other files.
@@ -50,14 +64,20 @@ assertEquals(acute, "Acute angle");
5064
// When the angle is greater than 90 degrees and less than 180 degrees,
5165
// Then the function should return "Obtuse angle"
5266
const obtuse = getAngleType(120);
67+
5368
// ====> write your test here, and then add a line to pass the test in the function above
69+
assertEquals(obtuse, "Obtuse angle");
5470

5571
// Case 4: Identify Straight Angles:
5672
// When the angle is exactly 180 degrees,
5773
// Then the function should return "Straight angle"
5874
// ====> write your test here, and then add a line to pass the test in the function above
75+
const straight = getAngleType(180);
76+
assertEquals(straight, "Straight angle");
5977

6078
// Case 5: Identify Reflex Angles:
6179
// When the angle is greater than 180 degrees and less than 360 degrees,
6280
// Then the function should return "Reflex angle"
63-
// ====> write your test here, and then add a line to pass the test in the function above
81+
// ====> write your test here, and then add a line to pass the test in the function above
82+
const reflex = getAngleType(270);
83+
assertEquals(reflex, "Reflex angle");

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This statement loads the getAngleType function you wrote in the implement directory.
22
// We will use the same function, but write tests for it using Jest in this file.
3+
const { test } = require("picomatch");
34
const getAngleType = require("../implement/1-get-angle-type");
45

56
test("should identify right angle (90°)", () => {
@@ -13,14 +14,30 @@ test("should identify right angle (90°)", () => {
1314
// When the angle is less than 90 degrees,
1415
// Then the function should return "Acute angle"
1516

17+
test("should identify acute angle (<90°)", () => {
18+
expect(getAngleType(45)).toEqual("Acute angle");
19+
})
20+
1621
// Case 3: Identify Obtuse Angles:
1722
// When the angle is greater than 90 degrees and less than 180 degrees,
1823
// Then the function should return "Obtuse angle"
1924

25+
test("should identify obtuse angle (>90° and <180°)", () => {
26+
expect(getAngleType(120)).toEqual("Obtuse angle");
27+
})
28+
2029
// Case 4: Identify Straight Angles:
2130
// When the angle is exactly 180 degrees,
2231
// Then the function should return "Straight angle"
2332

33+
test("should identify straight angle (180°)", () => {
34+
expect(getAngleType(180)).toEqual("Straight angle");
35+
})
36+
2437
// Case 5: Identify Reflex Angles:
2538
// When the angle is greater than 180 degrees and less than 360 degrees,
2639
// Then the function should return "Reflex angle"
40+
41+
test("should identify reflex angle (>180° and <360°)", () => {
42+
expect(getAngleType(270)).toEqual("Reflex angle");
43+
})

0 commit comments

Comments
 (0)