Skip to content

Commit b81aed6

Browse files
committed
Glasgow | Jan-26 | Fattouma Ouannassi | Sprint 3 | Coursework 3 implement and rewrite
<!-- You must title your PR like this: Region | Cohort | FirstName LastName | Sprint | Assignment Title For example, London | 25-ITP-May | Carol Owen | Sprint 1 | Alarm Clock Fill in the template below - remove any sections that don't apply. Complete the self checklist - replace each empty box in the checklist [ ] with a [x]. Add the label "Needs Review" and you will get review. Respond to volunteer reviews until the volunteer marks it as "Complete". Please note: if the PR template is not filled as described above, an automatic GitHub bot will give feedback in the "Conversation" tab of the pull request and not allow the "Needs Review" label to be added until it's fixed. --> ## Learners, PR Template Self checklist - [x] I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title - [x] My changes meet the requirements of the task - [x] I have tested my changes - [x] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/reviewing/style-guide/) ## Changelist This project (sprint 3) focuses on learning how to use JavaScript methods and test them. ## Questions /
1 parent 124ae45 commit b81aed6

File tree

1 file changed

+72
-6
lines changed

1 file changed

+72
-6
lines changed

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

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,90 @@
1414
// After you have implemented the function, write tests to cover all the cases, and
1515
// execute the code to ensure all tests pass.
1616

17-
function getAngleType(angle) {
17+
//function getAngleType(angle) {
1818
// TODO: Implement this function
19+
20+
// Implement a function getAngleType
21+
function getAngleType(angle) {
22+
if (angle > 0 && angle < 90) {
23+
return "Acute angle";
24+
} else if (angle === 90) {
25+
return "Right angle";
26+
} else if (angle > 90 && angle < 180) {
27+
return "Obtuse angle";
28+
} else if (angle === 180) {
29+
return "Straight angle";
30+
} else if (angle > 180 && angle < 360) {
31+
return "Reflex angle";
32+
} else {
33+
return "Invalid angle";
34+
}
35+
}
36+
37+
// Export for use in other files / Jest tests
38+
//module.exports = getAngleType;
39+
40+
// Helper function for assertions
41+
function assertEquals(actualOutput, targetOutput) {
42+
console.assert(
43+
actualOutput === targetOutput,
44+
`Expected ${actualOutput} to equal ${targetOutput}`
45+
);
1946
}
2047

48+
2149
// The line below allows us to load the getAngleType function into tests in other files.
2250
// This will be useful in the "rewrite tests with jest" step.
23-
module.exports = getAngleType;
51+
//module.exports = getAngleType;
2452

2553
// This helper function is written to make our assertions easier to read.
2654
// If the actual output matches the target output, the test will pass
27-
function assertEquals(actualOutput, targetOutput) {
55+
/*function assertEquals(actualOutput, targetOutput) {
2856
console.assert(
2957
actualOutput === targetOutput,
3058
`Expected ${actualOutput} to equal ${targetOutput}`
3159
);
32-
}
60+
}*/
3361

3462
// TODO: Write tests to cover all cases, including boundary and invalid cases.
3563
// Example: Identify Right Angles
36-
const right = getAngleType(90);
37-
assertEquals(right, "Right angle");
64+
// ===> TESTS
65+
66+
// Acute angles (0 < angle < 90)
67+
console.log("Testing Acute angles...");
68+
assertEquals(getAngleType(1), "Acute angle");
69+
assertEquals(getAngleType(45), "Acute angle");
70+
assertEquals(getAngleType(89), "Acute angle");
71+
assertEquals(getAngleType(0.5), "Acute angle");
72+
73+
// Right angle (=90)
74+
console.log("Testing Right angle...");
75+
assertEquals(getAngleType(90), "Right angle");
76+
77+
// Obtuse angles (90 < angle < 180)
78+
console.log("Testing Obtuse angles...");
79+
assertEquals(getAngleType(91), "Obtuse angle");
80+
assertEquals(getAngleType(135), "Obtuse angle");
81+
assertEquals(getAngleType(179), "Obtuse angle");
82+
83+
// Straight angle (=180)
84+
console.log("Testing Straight angle...");
85+
assertEquals(getAngleType(180), "Straight angle");
86+
87+
// Reflex angles (180 < angle < 360)
88+
console.log("Testing Reflex angles...");
89+
assertEquals(getAngleType(181), "Reflex angle");
90+
assertEquals(getAngleType(270), "Reflex angle");
91+
assertEquals(getAngleType(359), "Reflex angle");
92+
assertEquals(getAngleType(359.9), "Reflex angle");
93+
94+
// Invalid angles (angle <= 0 or angle >= 360)
95+
console.log("Testing Invalid angles...");
96+
assertEquals(getAngleType(0), "Invalid angle");
97+
assertEquals(getAngleType(-1), "Invalid angle");
98+
assertEquals(getAngleType(-45), "Invalid angle");
99+
assertEquals(getAngleType(360), "Invalid angle");
100+
assertEquals(getAngleType(361), "Invalid angle");
101+
assertEquals(getAngleType(720), "Invalid angle");
102+
103+
console.log("\n✅ All tests completed successfully!");

0 commit comments

Comments
 (0)