Skip to content

Sheffeild | ITP-May-2025 | WALEED-YAHYA SALIH-TAHA |Sprint 3 #644

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// Build up your function case by case, writing tests as you go
// The first test and case is written for you. The next case has a test, but no code.
// Execute this script in your terminal
// node 1-get-angle-type.js
//node 1-get-angle-type.js
// The assertion error will tell you what the expected output is
// Write the code to pass the test
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
// read to the end, complete line 36, then pass your test here
}

Expand Down Expand Up @@ -43,14 +47,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"
const Straight = getAngleType(180);
assertEquals(Straight,"Straight angle");
// ====> write your test here, and then add a line to pass the test in the function above

// 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"
const Reflex = getAngleType(200);
assertEquals(Reflex,"Reflex angle");
// ====> write your test here, and then add a line to pass the test in the function above
4 changes: 4 additions & 0 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator >= denominator)return false;

}

// here's our helper again
Expand Down Expand Up @@ -40,13 +42,15 @@ assertEquals(improperFraction, false);
// 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);
assertEquals(negativeFraction,true);
// ====> 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(improperFraction,false);
// ====> complete with your assertion

// Stretch:
Expand Down
24 changes: 22 additions & 2 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@
// 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) {
if (rank === "A") return 11;
if (!card || typeof card !== "string") return "Invalid card format";
//extracting the rank of the card
const rank = card.slice(0, -1).trim();
}
//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN.
if (rank === "A") return 11;
//For numerical cards, we return the number
else if (!isNaN(rank) >= 2 && Number(rank) <= 10) return Number(rank);
//For face cards, we return 10
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10;
//If the card is invalid, we throw an error
else return("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
Expand All @@ -33,19 +47,25 @@ assertEquals(aceofSpades, 11);
// 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♥");
assertEquals(fiveofHearts,5);
// ====> write your test here, and then add a line to pass the test in the function above

// 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 kingofhearts = getCardValue("J","K","Q");
assertEquals(kingofhearts,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.
const aceofDiamonds = getCardValue("A:diamonds:");
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."
const Invalidcardrank = getCardValue("1:diamonds:");
assert.strictEqual(Invalidcardrank,"Invalid card rank");
5 changes: 5 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
// replace with your completed function from key-implement

}
module.exports = getAngleType;



Expand Down
21 changes: 21 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,38 @@ test("should identify right angle (90°)", () => {
// make your test descriptions as clear and readable as possible

// Case 2: Identify Acute Angles:
test("should identify acute angles (less than 90°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

// Case 3: Identify Obtuse Angles:
test("should identify obtuse angles (between 90° and 180°)", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"

// Case 4: Identify Straight Angles:
test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

// Case 5: Identify Reflex Angles:
test("should identify reflex angles (between 180° and 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
6 changes: 6 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator === denominator)return false;
if (numerator > denominator)return false;
if (Math.abs(numerator) < Math.abs(denominator)) return true;
return false;


// add your completed function from key-implement here
}

Expand Down
16 changes: 16 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
const isProperFraction = require("./2-is-proper-fraction");


test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});

// Case 2: Identify Improper Fractions:
test("should return false for an Improper fraction", () => {
expect(isProperFraction(6, 3)).toEqual(false);
});

test("should return false for a negative improper fraction", () => {
expect(isProperFraction(-7, 4)).toEqual(false);
});

// Case 3: Identify Negative Fractions:
test("should return true for a negative proper fraction", () => {
expect(isProperFraction(3, -5)).toEqual(true);
expect(isProperFraction(-3, 5)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for equal numerator and denominator", () => {
expect(isEqualNumeratorAndDenominator(5, 5)).toEqual(false);
});

7 changes: 7 additions & 0 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;

}
const rank = card.slice(0, -1);
if (rank === "A") return 11;
(["K", "Q", "J", "10"].includes(rank)) return 10;
(!isNaN(rank) && rank >= 2 && rank <= 9) return Number(rank);
throw new Error("Invalid card rank");

module.exports = getCardValue;
27 changes: 26 additions & 1 deletion Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
const getCardValue = require("./3-get-card-value");

test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");

expect(aceofSpades).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:


test("should return the correct value for number cards (2-10)", () => {
expect(getCardValue("2♦")).toEqual(2);
expect(getCardValue("5♣")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
});

test("should return 10 for face cards (J, Q, K)", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
});
test("should return 11 for Ace", () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
});

test("should throw an error for invalid cards", () => {
expect(() => getCardValue("1♠")).toThrow("Invalid card rank");
expect(() => getCardValue("Z♦")).toThrow("Invalid card rank");
expect(() => getCardValue("15♥")).toThrow("Invalid card rank");
expect(() => getCardValue("X♣")).toThrow("Invalid card rank");
});
3 changes: 2 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
//return 5
return stringOfCharacters.split(findCharacter).length - 1;
}

module.exports = countChar;
29 changes: 29 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,32 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 when the character is not found", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should be case-sensitive", () => {
const str = "Millena";
const char = "m";
const count = countChar(str, char);
expect(count).toEqual(0);
});


test("should count spaces as characters", () => {
const str = "Millena Mesfin";
const char = " ";
const count = countChar(str, char);
expect(count).toEqual(1);
});

test("should return 0 for an empty string", () => {
const str = "";
const char = "m";
const count = countChar(str, char);
expect(count).toEqual(0);
});
13 changes: 11 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function getOrdinalNumber(num) {
return "1st";
}
if (num < 1 || !Number.isInteger(num)) throw new Error("Input must be a positive integer");

const specialCases = [11, 12, 13];
const suffixes = ["th", "st", "nd", "rd"];
const lastDigit = num % 10;
const lastTwoDigits = num % 100;

return num + (specialCases.includes(lastTwoDigits) ? "th" : suffixes[lastDigit] || "th");
}



module.exports = getOrdinalNumber;
43 changes: 43 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,46 @@ const getOrdinalNumber = require("./get-ordinal-number");
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});
test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});

test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});

test("should return '12th' for 12", () => {
expect(getOrdinalNumber(12)).toEqual("12th");
});

test("should return '13th' for 13", () => {
expect(getOrdinalNumber(13)).toEqual("13th");
});

test("should return '21st' for 21", () => {
expect(getOrdinalNumber(21)).toEqual("21st");
});

test("should return '102nd' for 102", () => {
expect(getOrdinalNumber(102)).toEqual("102nd");
});

test("should return '113th' for 113", () => {
expect(getOrdinalNumber(113)).toEqual("113th");
});

test("should return '101st' for 101", () => {
expect(getOrdinalNumber(101)).toEqual("101st");
});

test("should return '1000th' for 1000", () => {
expect(getOrdinalNumber(1000)).toEqual("1000th");
});
Loading