Skip to content

Sheffield | May-2025 | Hassan Osman | Sprint-3 #580

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 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9b98e48
implemented & tested function for all angle types
HassanOHOsman Jun 18, 2025
1e65655
tested & implemented different card types
HassanOHOsman Jun 18, 2025
5634292
implemented and tested the char count
HassanOHOsman Jun 19, 2025
5d17a56
implemented and tested ordinal number function
HassanOHOsman Jun 19, 2025
531b3ed
implemented and tested the repeat function
HassanOHOsman Jun 19, 2025
1472a6e
changed to make angles <=0 evaluates to "invalid"
HassanOHOsman Jun 28, 2025
0286d78
updated the last test description for more clarity.
HassanOHOsman Jun 28, 2025
5bd333e
simplified the conditions of my function
HassanOHOsman Jun 28, 2025
3498122
updated function implementation & tests
HassanOHOsman Jun 28, 2025
33809e8
updated card function implementation & test
HassanOHOsman Jun 28, 2025
f8895ad
changed ordinal number function to widen range
HassanOHOsman Jun 29, 2025
06411c8
corrected my empty string return
HassanOHOsman Jun 29, 2025
489b22f
simplified my function
HassanOHOsman Jun 29, 2025
6284562
added Math.abs()
HassanOHOsman Jun 30, 2025
c4a2aca
edited function to cover different suits & ranks
HassanOHOsman Jun 30, 2025
7c4389d
updated tests descriptions
HassanOHOsman Jun 30, 2025
499bcf1
updated tests descriptions
HassanOHOsman Jun 30, 2025
34dd33f
updated the error message
HassanOHOsman Jun 30, 2025
784a678
refactored Face Cards(J,Q,K) test further
HassanOHOsman Jul 1, 2025
0ec98ea
refactored tests for (2-10) cards further
HassanOHOsman Jul 1, 2025
f7bfacf
corrected mistakes in a few of ordinal num tests
HassanOHOsman Jul 1, 2025
8461178
removed a bug from ordinal number'd function
HassanOHOsman Jul 1, 2025
16a010c
further refactored ordinal numbers tests
HassanOHOsman Jul 1, 2025
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
7 changes: 5 additions & 2 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (0 < angle && 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";
return "invalid";
}


Expand Down
32 changes: 30 additions & 2 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,49 @@ 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
test("should identify Acute agles", () => {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(88)).toEqual("Acute angle");
});



// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"


test("should identify Obtuse angle", () => {
expect(getAngleType(99)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse 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 Straight angle", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});



// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

test("should identify Reflex angle", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex 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 angle not in range (0, 360)", () => {
expect(getAngleType(360)).toEqual("invalid");
expect(getAngleType(370)).toEqual("invalid");
});
7 changes: 5 additions & 2 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (Math.abs(numerator/denominator) >= 1) {
return false;
} else {
return true;
}
}

module.exports = isProperFraction;
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
Expand Up @@ -6,6 +6,22 @@ test("should return true for a proper fraction", () => {

// Case 2: Identify Improper Fractions:

test("should return false for an improper fraction", () => {
expect(isProperFraction(11, 3)).toEqual(false);
expect(isProperFraction(7, 2)).toEqual(false);
});


// Case 3: Identify Negative Fractions:

test("should return a negative fraction", () => {
expect(isProperFraction(-2, 3)).toEqual(true);
expect(isProperFraction(18, -7)).toEqual(false);
});


// Case 4: Identify Equal Numerator and Denominator:

test("should return a whole number", () => {
expect(isProperFraction(4, 4)).toEqual(false);
});
27 changes: 25 additions & 2 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
const rank = card.slice(0, 1)
switch(rank) {
case "A":
return 11;
break;
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "10":
return Number(rank);
break;
case "J":
case "K":
case "Q":
return 10;
break;
default:
throw new Error("Invalid card rank");

}
}
module.exports = getCardValue;
35 changes: 34 additions & 1 deletion Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@ 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):
test("should return 2-10 for cards rank (2-10)", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("9♣︎")).toEqual(9);
expect(getCardValue("7♠")).toEqual(7);
});




// Case 3: Handle Face Cards (J, Q, K):
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);
});



// Case 4: Handle Ace (A):
test("should return 11 for Ace", () => {
const ace = getCardValue("A");
expect(ace).toEqual(11);
});

// Case 5: Handle Invalid Cards:
test("should throw Invalid card rank for invalid cards", () => {

let card = "Z♠"
expect(() => getCardValue(card)).toThrow("Invalid card rank");
});

test("should throw Invalid card rank for invalid cards", () => {

let card = "11♠"
expect(() => getCardValue(card)).toThrow("Invalid card rank");
});
4 changes: 2 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
function countChar(str, char) {
return str.split(char).length -1;
}

module.exports = countChar;
30 changes: 30 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,38 @@ test("should count multiple occurrences of a character", () => {
expect(count).toEqual(5);
});

test("should count multiple occurrences of a character", () => {
const str = "bandana";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(3);
});

test("should count multiple occurrences of a character", () => {
const str = "mississippi";
const char = "i";
const count = countChar(str, char);
expect(count).toEqual(4);

});

// Scenario: No Occurrences
// Given the input string str,
// 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 in a case-sensitive str", () => {
const str = "HHHHHH";
const char = "h";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should return 0 in a case-sensitive str", () => {
const str = "bubble";
const char = "B";
const count = countChar(str, char);
expect(count).toEqual(0);

});
22 changes: 21 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function getOrdinalNumber(num) {
return "1st";
const lastDigit = num % 10;
const lastTwoDigits = num % 100;
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
return `${num}th`;
}

switch(lastDigit) {
case 1:
return `${num}st`;
break;
case 2:
return `${num}nd`;
break;
case 3:
return `${num}rd`;
break;
default:
return `${num}th`;
}


}

module.exports = getOrdinalNumber;
Copy link
Contributor

@cjyuan cjyuan Jul 1, 2025

Choose a reason for hiding this comment

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

I don't think your implementation can pass some of the tests in this script. Have you tried executing this script to test your function implementation?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, some mistakes in the 2 expected values which have now been corrected.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ const getOrdinalNumber = require("./get-ordinal-number");
// When the number is 1,
// Then the function should return "1st"

test("should return '1st' for 1", () => {
test("should append 'st' to numbers ending with 1 and not ending with 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(41)).toEqual("41st");
});



test("should append 'nd' to numbers ending with 2", () => {
expect(getOrdinalNumber(62)).toEqual("62nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
});

test("should append 'rd' to numbers ending with 3", () => {
expect(getOrdinalNumber(93)).toEqual("93rd");
expect(getOrdinalNumber(3)).toEqual("3rd");
});


test("should append 'th' to numbers ending (4-9)", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(6)).toEqual("6th");
expect(getOrdinalNumber(9)).toEqual("9th");
});

test("should append 'th' to numbers ending (11-13)", () => {
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
14 changes: 11 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if(count > 0) {
return str.repeat(count);
} else if (count === 0) {
return "";
} else {
throw new Error("Invalid number");
}
}

module.exports = repeat;
module.exports = repeat;


21 changes: 21 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ test("should repeat the string count times", () => {
// When the repeat function is called with these inputs,
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.

test("should return the original string without repetition", () => {
const str = "hi";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hi");
});

// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeat function is called with these inputs,
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.

test("should return an empty string for count = 0", () => {
const str = "Good Morning";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});


// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.

test("should throw an error / return an error message", () => {
const str = "Bye";
const count = -3;
expect(() => repeat(str, count)).toThrow("Invalid number");
});