Skip to content

London | Emmanuel Gessessew | Module-Structuring-and-Testing-Data | sprint 3| WEEK 3 #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sprint-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getAngleType(angle) {
} else if (angle < 90) {
return "Acute angle";
// to get the obtuse angle
} else if (angle > 90 && angle < 180) {
} else if (90 < angle < 180) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case doesn't work - can you check what happens if you use the condition angle > 90 && angle < 180 instead of 90 < angle < 180, and explain why does one work and the other doesn't?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 90 < angle < 180 doesn't work in JavaScript because it evaluates 90 < angle first, resulting in a boolean (true or false), which is then compared to 180. JavaScript do nott support chained comparisons like Python.

return "Obtuse angle";
// to get the stright line, or angle
} else if (angle === 180) {
Expand All @@ -50,7 +50,7 @@ function getAngleType(angle) {
}
}


module.exports = getAngleType;



Expand Down
47 changes: 47 additions & 0 deletions Sprint-3/implement/getAngleType.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
test('should return "Right angle" exactly for 90 degrees', function() {
const currentInput = getAngleType (90);
const targetInput = "Right angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Acute angle" when degrees is less than 90 degrees', function() {
const currentInput = getAngleType (45);
const targetInput = "Acute angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Obtuse angle" when degrees are between 90 and 180 degrees', function() {
const currentInput = getAngleType(135);
const targetInput = "Obtuse angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Straight angle" exactly for 180 degrees', function() {
const currentInput = getAngleType(180);
const targetInput = "Straight angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Reflex angle" when degrees are between 180 and 360 degrees', function() {
const currentInput = getAngleType(270);
const targetInput = "Reflex angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Invalid angle" for angles less than 0 degrees', function() {
const currentInput = getAngleType(-45);
const targetInput = "Invalid angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Invalid angle" for angles equal to or greater than 360 degrees', function() {
const currentInput = getAngleType(360);
const targetInput = "Invalid angle";
expect(currentInput).toBe(targetInput);
});

test('should return "Invalid angle" for non-numeric inputs', function() {
const currentInput = getAngleType("hello");
const targetInput = "Invalid angle";
expect(currentInput).toBe(targetInput);
});
10 changes: 10 additions & 0 deletions Sprint-3/implement/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "week-4-test-example",
"description": "An example application showing how to write tests using the jest framework",
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^29.5.0"
}
}