-
-
Notifications
You must be signed in to change notification settings - Fork 195
Sheffield | May-2025 | WALEED-YAHYA SALIH-TAHA | Sprint-3 #652
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 all commits
56e3dbc
d4a0730
f6cd051
59a1e19
a0004a8
c7772a6
eb50828
b797a92
f5f36f5
a467519
18a93a1
3523e59
d6a2edf
67a05da
5a1570a
61decd0
8e295aa
4b2e240
a1f0f58
ec30fb1
a0595c0
eda20da
b0904d1
fca4456
71bac2d
3e96df9
2b1c9be
3a5be71
da42c37
c9b0ff6
fd37f69
f242d6a
fee695d
abcdfbf
af20de9
7076fc0
9ef7886
1b10f2d
7d4ba19
49b7c00
f85e00c
f3973af
3b2251a
58a71c3
1a74ee8
ebc99d8
af1e3ca
cab246a
a64cee4
a451aeb
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,18 +1,24 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
if (angle <= 0 || angle >= 360) return "Invalid angle"; | ||
if (angle < 90) return "Acute angle"; | ||
if (angle === 90) return "Right angle"; | ||
if (angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
return "Reflex angle"; // angle between 180 and 360 | ||
}; | ||
|
||
|
||
|
||
// 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 have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; | ||
console.log(getAngleType(45)); // Acute angle | ||
console.log(getAngleType(90)); // Right angle | ||
console.log(getAngleType(135)); // Obtuse angle | ||
console.log(getAngleType(180)); // Straight angle | ||
console.log(getAngleType(270)); // Reflex angle | ||
console.log(getAngleType(0)); // Invalid angle | ||
console.log(getAngleType(360)); // Invalid angle | ||
console.log(getAngleType(-10)); // Invalid angle | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
const getAngleType = require("./1-get-angle-type"); | ||
|
||
// Case 1: Identify Right Angles | ||
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" | ||
|
||
// 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" | ||
// Case 2: Identify Acute Angles (less than 90°) | ||
test("should identify acute angles (< 90°)", () => { | ||
expect(getAngleType(1)).toEqual("Acute angle"); | ||
expect(getAngleType(45)).toEqual("Acute angle"); | ||
expect(getAngleType(89)).toEqual("Acute angle"); | ||
}); | ||
|
||
// Case 3: Identify Obtuse Angles (90° < angle < 180°) | ||
test("should identify obtuse angles (between 90° and 180°)", () => { | ||
expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
expect(getAngleType(135)).toEqual("Obtuse angle"); | ||
expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
}); | ||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
|
||
test("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("reflex angle (181°)", () => { | ||
expect(getAngleType(181)).toEqual("Reflex angle"); | ||
expect(getAngleType(270)).toEqual("Reflex angle"); | ||
expect(getAngleType(359)).toEqual("Reflex angle"); | ||
}); | ||
// Case 6: Handle invalid angles (≤ 0 or ≥ 360) | ||
test("should identify invalid angles (≤ 0 or ≥ 360)", () => { | ||
expect(getAngleType(0)).toEqual("Invalid angle"); | ||
expect(getAngleType(-45)).toEqual("Invalid angle"); | ||
expect(getAngleType(360)).toEqual("Invalid angle"); | ||
expect(getAngleType(400)).toEqual("Invalid angle"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,54 @@ function isProperFraction(numerator, denominator) { | |
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
} | ||
function isProperFraction(numerator, denominator) { | ||
if (denominator === 0) return false; // Can't divide by zero | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
|
||
// here's our helper again | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
// Proper Fraction check: | ||
// Input: numerator = 2, denominator = 3 | ||
// target output: true | ||
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. | ||
assertEquals(isProperFraction(2, 3), true); // ✅ should pass | ||
|
||
// Improper Fraction check: | ||
// Input: numerator = 5, denominator = 2 | ||
// target output: false | ||
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false. | ||
assertEquals(isProperFraction(5, 2), false); // ✅ should pass | ||
|
||
// Negative Fraction check: | ||
// Input: numerator = -4, denominator = 7 | ||
// target output: true | ||
// 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 | ||
|
||
// 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); | ||
assertEquals(equalFraction, false); | ||
// ====> complete with your assertion | ||
|
||
// 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 is zero, | ||
// which is less than the denominator. The function should return true. | ||
const zeroNumerator = isProperFraction(0, 5); | ||
assertEquals(zeroNumerator, true); // ✅ should pass | ||
Comment on lines
+52
to
+53
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. Technically 0 is not considered a proper fraction. :) |
||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,72 @@ | ||
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck | ||
|
||
// You will need to implement a function getCardValue | ||
// the function takes a single parameter, a string representing a playing card | ||
// the function should return the numerical value of the card | ||
// the first test and first case is written for you | ||
// complete the rest of the tests and cases | ||
// write one test at a time, and make it pass, build your solution up methodically | ||
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // Get the rank (everything except the last character) | ||
if (rank === "A") return 11; | ||
if (["J", "Q", "K"].includes(rank)) return 10; | ||
if (rank >= "2" && rank <= "9") return parseInt(rank, 10); | ||
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. Strings are compared differently in the JS language. Does your function return the value you expected from each of the following function calls?
|
||
if (rank === "10") return 10; // Handle the 10 card explicitly | ||
throw new Error("Invalid card rank"); | ||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
// we're going to use this helper function to make our assertions easier to read | ||
// if the actual output matches the target output, the test will pass | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
// Acceptance criteria: | ||
|
||
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), | ||
// When the function getCardValue is called with this card string as input, | ||
// Then it should return the numerical card value | ||
const aceofSpades = getCardValue("A♠"); | ||
assertEquals(aceofSpades, 11); | ||
|
||
// Handle Number Cards (2-10): | ||
// Given a card with a rank between "2" and "9", | ||
// When the function is called with such a card, | ||
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
const fiveofHearts = getCardValue("5♥"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
assertEquals(fiveofHearts, 5); | ||
|
||
// Handle Face Cards (J, Q, K): | ||
// Given a card with a rank of "10," "J," "Q," or "K", | ||
// When the function is called with such a card, | ||
// Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
const jackOfDiamonds = getCardValue("J♦"); | ||
assertEquals(jackOfDiamonds, 10); | ||
const queenOfClubs = getCardValue("Q♣"); | ||
assertEquals(queenOfClubs, 10); | ||
const kingOfSpades = getCardValue("K♠"); | ||
assertEquals(kingOfSpades, 10); | ||
|
||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
// When the function is called with an Ace, | ||
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
// (Note: In some games, the Ace can also be worth 1 point, but for this function, we will assume it is always worth 11 points.) | ||
const aceOfDiamonds = getCardValue("A♦"); | ||
assertEquals(aceOfDiamonds, 11); | ||
|
||
// Handle Invalid Cards: | ||
// Given a card with an invalid rank (neither a number nor a recognized face card), | ||
// When the function is called with such a card, | ||
// Then it should throw an error indicating "Invalid card rank." | ||
try { | ||
getCardValue("Z♠"); // Invalid card | ||
} catch (error) { | ||
console.assert(error.message === "Invalid card rank", "Expected error for invalid card rank"); | ||
} | ||
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.
Unused code or code used solely for development purposes should be removed or, at the very least, commented out with clear justification.