-
-
Notifications
You must be signed in to change notification settings - Fork 219
LONDON | ITP-MAY-25 | TEWODROS BEKERE | Coursework/sprint-3 #602
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
Changes from all commits
9167e67
f9da79b
da2169b
6894bd8
cb1730c
55d8c9f
3a6390e
796a8cf
b014b98
7e10cb8
0771e60
c8ed1bb
e9ab61e
04360b4
ce4fb74
63dda1e
ab8f199
d96efd6
1fc4d18
3ea90b1
76a9808
5ed0d66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
if (angle > 0 && angle < 90) { | ||
return "Acute angle"; | ||
} else if (angle === 90) { | ||
return "Right angle"; | ||
} else if (angle > 90 && angle < 180) { | ||
return "Obtuse angle"; | ||
} else if (angle === 180) { | ||
return "Straight angle"; | ||
}else if (angle > 180 && angle < 360) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function looks good and covers the requirements. Nice job. The two checks for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This satisfies the criteria. |
||
return "Reflex angle"; | ||
} | ||
else { | ||
return "Invalid angle"; | ||
} | ||
|
||
} | ||
|
||
|
||
console.log(getAngleType(-90)); // Right angle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the comment match the output for this statement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
const getAngleType = require("./1-get-angle-type"); | ||
const getAngleType = require("./1-get-angle-type"); | ||
|
||
test("should identify right angle (90°)", () => { | ||
expect(getAngleType(90)).toEqual("Right angle"); | ||
}); | ||
|
||
|
||
// REPLACE the comments with the tests | ||
// make your test descriptions as clear and readable as possible | ||
|
||
// Case 2: Identify Acute Angles: | ||
// When the angle is less than 90 degrees, | ||
// Then the function should return "Acute angle" | ||
test("should identify acute angle (<90°)", () => { | ||
expect(getAngleType(45)).toEqual("Acute angle"); | ||
}); | ||
|
||
// Case 3: Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
test("should identify obtuse angle (>90° and <180°)", () => { | ||
expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
}); | ||
|
||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
test("should identify straight angle (180°)", () => { | ||
expect(getAngleType(180)).toEqual("Straight angle"); | ||
}); | ||
|
||
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
test("should identify reflex angle (>180° and <360°)", () => { | ||
expect(getAngleType(270)).toEqual("Reflex angle"); | ||
}); | ||
// Case 6: Handle Invalid Angles: | ||
// When the angle is less than 0 degrees or greater than or equal to 360 degrees, | ||
// Then the function should return "Invalid angle" | ||
test("should handle invalid angle (<0° or >=360°)", () => { | ||
expect(getAngleType(-10)).toEqual("Invalid angle"); | ||
expect(getAngleType(360)).toEqual("Invalid angle"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is good that you used two expect statements here, for future tests this is a good practice. |
||
}); | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) return false; // Avoid division by zero | ||
if (numerator === 0) return true; // Zero is considered a proper fraction | ||
if (numerator < 0 || denominator < 0) return false; // Negative fractions are not proper | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good. Here would the |
||
} | ||
|
||
console.log(isProperFraction(0, 1)); | ||
console.log(isProperFraction(5,3)); | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,28 @@ const isProperFraction = require("./2-is-proper-fraction"); | |
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
expect(isProperFraction(1, 2)).toEqual(true); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
|
||
test("should return false for an improper fraction", () => { | ||
expect(isProperFraction(5, 3)).toEqual(false); | ||
expect(isProperFraction(3, 3)).toEqual(false); | ||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
|
||
test("should return false for negative fractions", () => { | ||
expect(isProperFraction(-2, 3)).toEqual(false); | ||
expect(isProperFraction(2, -3)).toEqual(false); | ||
expect(isProperFraction(-2, -3)).toEqual(false); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
|
||
test("should return false when numerator and denominator are equal", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test coverage looks good. |
||
expect(isProperFraction(4, 4)).toEqual(false); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
//return 11; | ||
if (card === 'A') { | ||
return 11; // Ace can be 11 or 1, but we'll | ||
} | ||
else if (card === 'K' || card === 'Q' || card === 'J') { | ||
return 10; // Face cards are worth 10 | ||
} | ||
else { | ||
return parseInt(card); // Number cards are worth their face value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good start, how would we handle cases where there is a rank and a number? (e.g. What about situations where the rank is a number that we do not expect? e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It throws an error: invalid card rank. |
||
} | ||
} | ||
console.log(getCardValue('A')); | ||
console.log(getCardValue('K')); | ||
console.log(getCardValue('J')); | ||
console.log(getCardValue('Q')); | ||
console.log(getCardValue('B')); | ||
|
||
module.exports = getCardValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you have added comments for handling edge cases for this function, seems like your requirements are well defined.
Perhaps this would be a good stretch for you to introduce logic for handling the denominator being zero.
How would you handle the situation where the numerator is
-4
& the denominator is3
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the zero denominator to throw an error, and for this logic (-4, 3) it's handled by ' if (numerator < denominator) return true;'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding that check to make sure the denominator is non-zero.