-
-
Notifications
You must be signed in to change notification settings - Fork 195
London | ITP-May-2025 | Surafel Workneh| Sprint-3 #637
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
base: main
Are you sure you want to change the base?
Changes from 23 commits
ba7c348
e6d6e76
cea3512
d375cee
f66a15a
e67b162
0a7cda4
87fc686
a52f2c1
e2c54d6
1014714
af66632
a5879e7
e255a25
9b9d6fa
4c03b27
d0371be
094657b
d457ddd
729f88f
d17fa1d
affd78a
93fae64
635a1a0
2bfd808
7c6010a
eed725e
9c478cd
8cb7495
14e256e
922ebf5
ddf577d
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 |
---|---|---|
|
@@ -8,8 +8,16 @@ | |
// Then, write the next test! :) Go through this process until all the cases are implemented | ||
|
||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// read to the end, complete line 36, then pass your test here | ||
if (angle === 90) return "Right angle"; | ||
// read to the end, complete line 36, then pass your test here | ||
// if the angle is less than 90, return "Acute angle" | ||
if (angle < 90) return "Acute angle"; | ||
// if the angle is greater than 90 and less than 180, return "Obtuse angle" | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
// if the angle is exactly 180, return "Straight angle" | ||
if (angle === 180) return "Straight angle"; | ||
// if the angle is greater than 180 and less than 360, return "Reflex angle" | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
} | ||
|
||
// we're going to use this helper function to make our assertions easier to read | ||
|
@@ -20,7 +28,7 @@ function assertEquals(actualOutput, targetOutput) { | |
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
|
||
console.log("hello there"); | ||
// Acceptance criteria: | ||
|
||
// Given an angle in degrees, | ||
|
@@ -43,14 +51,19 @@ assertEquals(acute, "Acute angle"); | |
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
const obtuse = getAngleType(120); | ||
assertEquals(obtuse, "Obtuse angle"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
const straightAngle = getAngleType(180); | ||
assertEquals(straightAngle, "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" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
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. Hi Surafel, good work on this. Just check that your function returns something for angles like 360 or any number outside 0 to 360. Right now, it doesn’t handle those cases. |
||
const reflex = getAngleType(270); | ||
assertEquals(reflex, "Reflex angle"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
|
||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// if (numerator < denominator) return true; it will not work for negative numbers | ||
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. your function should also check if the denominator is zero. If it is, the function should return false because a fraction cannot have a zero as the denominator. Try adding that check. Keep going, you are doing well! 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. I resolved the comments as per your requirements . thank you |
||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
// here's our helper again | ||
|
@@ -41,13 +42,28 @@ assertEquals(improperFraction, false); | |
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
const negativeFraction = isProperFraction(-4, 7); | ||
// ====> complete with your assertion | ||
assertEquals(negativeFraction, true); | ||
|
||
// Equal Numerator and Denominator check: | ||
// Input: numerator = 3, denominator = 3 | ||
// target output: false | ||
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
const equalFraction = isProperFraction(3, 3); | ||
// ====> complete with your assertion | ||
|
||
assertEquals(equalFraction, false); | ||
// Stretch: | ||
// What other scenarios could you test for? | ||
|
||
// Zero Numerator check: | ||
// Input: numerator = 0, denominator = 5 | ||
// target output: true | ||
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true. | ||
const zeroNumerator = isProperFraction(0, 5); | ||
assertEquals(zeroNumerator, true); | ||
|
||
// Zero Denominator check: | ||
// Input: numerator = 4, denominator = 0 | ||
// target output: false | ||
// Explanation: A fraction with a zero denominator is undefined. The function should return false to indicate it's not a valid proper fraction. | ||
const zeroDenominator = isProperFraction(4, 0); | ||
assertEquals(zeroDenominator, false); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
// Step 1: Check for a right angle (exactly 90 degrees) | ||
if (angle === 90) return "Right angle"; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
// Step 2: Check for a straight angle (exactly 180 degrees) | ||
if (angle === 180) return "Straight angle"; | ||
|
||
// Step 3: Check for an acute angle (between 0 and 90) | ||
if (angle > 0 && angle < 90) return "Acute Angle"; | ||
|
||
// Step 4: Check for an obtuse angle (between 90 and 180) | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
// Step 5: Check for a reflex angle (between 180 and 360) | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
|
||
// Step 6: Handle invalid or unsupported input | ||
return "Invalid angle"; | ||
} | ||
|
||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; | ||
|
||
// console.log(getAngleType(90)); // "Right angle" | ||
// console.log(getAngleType(180)); // "Straight angle" | ||
// console.log(getAngleType(45)); // "Acute angle" | ||
// console.log(getAngleType(120)); // "Obtuse angle" | ||
// console.log(getAngleType(0)); // "Invalid angle" | ||
// console.log(getAngleType(200)); // "Invalid angle" | ||
// console.log(getAngleType(90.5)); // "Invalid angle" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
const getAngleType = require("./1-get-angle-type"); | ||
const getAngleType = require("./1-get-angle-type"); // Import the function to be tested | ||
|
||
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 Angles (< 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 && <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 Straight Angle (> 180 && < 360)", () => { | ||
expect(getAngleType(278)).toEqual("Reflex angle"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
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 || denominator < 0) return false; // Proper fractions are positive | ||
if (numerator < denominator) return true; // Proper if numerator < denominator | ||
return false; // Otherwise, it's improper | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; | ||
// Test cases for the isProperFraction function | ||
console.log(isProperFraction(1, 2)); // true | ||
console.log(isProperFraction(3, 4)); // true | ||
console.log(isProperFraction(5, 5)); // false | ||
console.log(isProperFraction(7, 6)); // false | ||
console.log(isProperFraction(0, 1)); // true | ||
console.log(isProperFraction(1, 0)); // false (denominator is zero) | ||
console.log(isProperFraction(-1, 2)); // false (negative numerator) | ||
console.log(isProperFraction(1, -2)); // false (negative denominator) | ||
console.log(isProperFraction(-1, -2)); // false (both negative) | ||
console.log(isProperFraction(2, 3)); // true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
const isProperFraction = require("./2-is-proper-fraction"); | ||
function isProperFraction(numerator, denominator) { | ||
// Case 1: Check for zero denominator (undefined) | ||
if (denominator === 0) return false; | ||
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
}); | ||
// Case 2: Check for negative values (numerator or denominator) | ||
if (numerator < 0 || denominator < 0) return false; | ||
|
||
// Case 2: Identify Improper Fractions: | ||
// Case 3: Check for equal numerator and denominator | ||
if (numerator === denominator) return false; | ||
|
||
// Case 3: Identify Negative Fractions: | ||
// Case 4: Check for proper fraction (numerator < denominator) | ||
return numerator < denominator; | ||
} | ||
module.exports = isProperFraction; | ||
// usage examples | ||
console.log(isProperFraction(2, 3)); // true | ||
console.log(isProperFraction(5, 3)); // false | ||
console.log(isProperFraction(3, 3)); // false | ||
console.log(isProperFraction(-2, 3)); // false | ||
console.log(isProperFraction(2, -3)); // false | ||
console.log(isProperFraction(0, 5)); // true (0 < 5) | ||
console.log(isProperFraction(2, 2)); // false | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
// Test cases for the isProperFraction function | ||
// test("should return true for a proper fraction", () => { | ||
// expect(isProperFraction(2, 3)).toEqual(true); | ||
// }); |
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; | ||
// replace with your code from key-implement | ||
// return 11; // always return 11 for testing purposes that is wrong | ||
const rank = card.slice(0, -1); // Extract rank (everything except the last character) | ||
if (rank === "A") return 11; // handle Ace as 11 | ||
if (["K", "Q", "J"].includes(rank)) return 10; // handle face cards as 10 | ||
const numerincRank = parseInt(rank); //Handle number cards 2–9 | ||
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's a typo in numerincRank , it should be numericRank. 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. spelling corrected |
||
if (numerincRank >= 2 && numerincRank <= 9) { | ||
return numerincRank; // Return the numeric value for cards 2-9 | ||
} | ||
// Invalid card rank | ||
return 0; | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; | ||
|
||
// // Test cases | ||
console.log(getCardValue("A♠")); // 11 | ||
console.log(getCardValue("7♥")); // 7 | ||
console.log(getCardValue("K♦")); // 10 | ||
console.log(getCardValue("A♣")); // 11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 7 for 7 of Hearts", () => { | ||
const sevenOfHearts = getCardValue("7♥"); | ||
expect(sevenOfHearts).toEqual(7); | ||
}); | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for King of Diamonds", () => { | ||
const kingOfDiamonds = getCardValue("K♦"); | ||
expect(kingOfDiamonds).toEqual(10); | ||
}); | ||
// Case 4: Handle Ace (A): | ||
test("should return 11 for Ace of Clubs", () => { | ||
const aceOfClubs = getCardValue("A♣"); | ||
expect(aceOfClubs).toEqual(11); | ||
}); | ||
// Case 5: Handle Invalid Cards: | ||
test("should return 0 for invalid card 'X♠'", () => { | ||
const invalidCard = getCardValue("X♠"); | ||
expect(invalidCard).toEqual(0); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
// return 5; //This will always return 5, regardless of the inputs. So it’s just a placeholder. | ||
return stringOfCharacters.split(findCharacter).length - 1; | ||
} | ||
|
||
module.exports = countChar; | ||
module.exports = countChar; | ||
|
||
// console.log(countChar("hello", "l")); // 2 | ||
// console.log(countChar("hello world", "o")); // 2 | ||
// console.log(countChar("banana", "a")); // 3 | ||
// console.log(countChar("mississippi", "i")); // 5 |
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.
Hi Surafel,I noticed filePath, lastSlashIndex, and base are used without being declared earlier in the code. You’ll need to define those variables before using them so the rest of your logic works correctly.
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 need to clean this code which shouldn’t be in sprint-3 at the first. so I will correct and push in sprint-1