Skip to content

Sheffield | May-2025 | Declan Williams | Sprint-3 #623

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 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
be25f2c
Implement acute angle identification in getAngleType function and add…
CatchingKiyoko Jun 17, 2025
4fa86db
Fix syntax error in acute angle test case
CatchingKiyoko Jun 17, 2025
d317d4f
Implement angle type identification for obtuse, straight, and reflex …
CatchingKiyoko Jun 17, 2025
dea34f8
Add tests for identifying obtuse angles in getAngleType function
CatchingKiyoko Jun 17, 2025
952fd14
Add test cases for identifying reflex angles in getAngleType function
CatchingKiyoko Jun 17, 2025
8cf3f58
Implement acute angle identification in getAngleType function
CatchingKiyoko Jun 18, 2025
6da0615
Implement obtuse angle identification in getAngleType function and ad…
CatchingKiyoko Jun 18, 2025
45209eb
Implement straight angle identification in getAngleType function and …
CatchingKiyoko Jun 18, 2025
37f345d
Implement reflex angle identification in getAngleType function and ad…
CatchingKiyoko Jun 18, 2025
ed4eaf3
Implement card value retrieval for face cards and number cards in get…
CatchingKiyoko Jun 23, 2025
a0d4fcf
Implement numerical value retrieval for cards 2-9 in getCardValue fun…
CatchingKiyoko Jun 23, 2025
d32c392
Enhance getCardValue function comments and add error handling for inv…
CatchingKiyoko Jun 23, 2025
e7f3d74
Fix typo in error message assertion for invalid card rank in getCardV…
CatchingKiyoko Jun 23, 2025
2e2d63c
Implement card value retrieval for all ranks in getCardValue function
CatchingKiyoko Jun 23, 2025
900385e
Add tests for number card values 2-10 in getCardValue function
CatchingKiyoko Jun 23, 2025
67c92c2
Add tests for face cards (J, Q, K) in getCardValue function
CatchingKiyoko Jun 23, 2025
60ed74f
add tests for handling Aces in getCardValue function
CatchingKiyoko Jun 23, 2025
bcdba1c
fix: correct expect statement for Ace value in getCardValue tests
CatchingKiyoko Jun 23, 2025
a16c211
add test for handling invalid card ranks in getCardValue function
CatchingKiyoko Jun 23, 2025
aced4d1
refactor: implement character counting logic in countChar function
CatchingKiyoko Jun 25, 2025
0a913b0
add test for handling no occurrences of a character in countChar func…
CatchingKiyoko Jun 25, 2025
de7632b
refactor: implement getOrdinalNumber function to return correct ordin…
CatchingKiyoko Jun 27, 2025
aa7b3ee
reimplmented module.exports for jest tests
CatchingKiyoko Jun 27, 2025
d2a8646
fix: correct ordinal suffix casing in getOrdinalNumber function
CatchingKiyoko Jun 27, 2025
9798ed9
refactor: remove console.log statements from getOrdinalNumber function
CatchingKiyoko Jun 27, 2025
63a66e2
test: add test cases for ordinal numbers 2 and 3 in getOrdinalNumber …
CatchingKiyoko Jun 27, 2025
c89c3b8
test: enhance test cases for ordinal numbers 1, 2, and 3 in getOrdina…
CatchingKiyoko Jun 27, 2025
2b44bf7
fix: correct conditional check for special cases in getOrdinalNumber …
CatchingKiyoko Jun 27, 2025
df5287d
test: update test descriptions for ordinal numbers and implemented a…
CatchingKiyoko Jun 27, 2025
1f02ed6
implemented repeat function with error handling and edge cases with …
CatchingKiyoko Jun 28, 2025
900db99
fix: correct typo in error message for negative count in repeat function
CatchingKiyoko Jun 28, 2025
5d2265b
refactor: comment out console log examples in repeat function
CatchingKiyoko Jun 28, 2025
525641a
test: add test case for returning original string when count is 1
CatchingKiyoko Jun 28, 2025
4f81c7d
test: add test case for handling count of 0 in repeat function
CatchingKiyoko Jun 28, 2025
d34ba19
test: add test case for handling negative count in repeat function
CatchingKiyoko Jun 28, 2025
dd38ca5
fix: add missing assertions for negative and equal fraction checks
CatchingKiyoko Jun 28, 2025
5798163
fix: clarify return statement in isProperFraction function
CatchingKiyoko Jun 28, 2025
a8d9ac3
test: add missing test case for improper fraction
CatchingKiyoko Jun 28, 2025
1a34fcf
test: add missing test case for negative fraction
CatchingKiyoko Jun 28, 2025
c5d4342
test: add missing test case for equal fraction
CatchingKiyoko Jun 28, 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
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 @@ -9,6 +9,10 @@

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (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"
// ====> write your test here, and then add a line to pass the test in the function above
const straight = getAngleType(180);
assertEquals(straight, "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
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
3 changes: 3 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,7 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
else return false;
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +42,15 @@ 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(properFraction, 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?
43 changes: 38 additions & 5 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@
// 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;
var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character)
if (rank === "A") return 11; // this checks for Aces
// Handle Number Cards (2-9)
if (rank === "2") return 2; // this checks for the twos
if (rank === "3") return 3; // this checks for the threes
if (rank === "4") return 4; // this checks for the fours
if (rank === "5") return 5; // this should check for fives
if (rank === "6") return 6; // this checks for the sixes
if (rank === "7") return 7; // this checks for the sevens
if (rank === "8") return 8; // this checks for the eights
if (rank === "9") return 9; // this checks for the nines
// Handle Face Cards (J, Q, K) And 10's
if (rank === "J") return 10; // this checks for Jacks
if (rank === "Q") return 10; // this checks for Queens
if (rank === "K") return 10; // this checks for Kings
if (rank === "10") return 10; // this checks for Tens
// if none of the above its an invalid card and throw an error
throw new Error("Invalid card rank."); // this will throw an error if the card is not a valid 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
Expand All @@ -32,20 +48,37 @@ assertEquals(aceofSpades, 11);
// 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
const fiveofHearts = getCardValue("5♥");
const sixofDiamonds = getCardValue("6♦");
const sevenofClubs = getCardValue("7♣");
const eightofSpades = getCardValue("8♠");
assertEquals(fiveofHearts, 5);
assertEquals(sixofDiamonds, 6);
assertEquals(sevenofClubs, 7);
assertEquals(eightofSpades, 8);

// 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♦");
const queenOfClubs = getCardValue("Q♣");
const kingOfSpades = getCardValue("K♠");
assertEquals(jackOfDiamonds, 10);
assertEquals(queenOfClubs, 10);
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.

// 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♠"); // this should throw an error of "Invalid card rank."
console.log("Test failed: Expected an error for invalid card rank.");
} catch(error){
assertEquals(error.message, "Invalid card rank.");
}
10 changes: 8 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,14 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (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";
}
Comment on lines +4 to 12
Copy link
Contributor

Choose a reason for hiding this comment

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

Your function can return undefined for some values of angle. To ensure reliability, please update the function so it always returns a defined value (which can be "Invalid angle") or throws an error. Functions that are expected to return a result should never return undefined.

Note: the spec fails to mention angles <= 0 are not "Acute angle".



Expand All @@ -10,7 +17,6 @@ function getAngleType(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
Expand Down
16 changes: 16 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 @@ -10,15 +10,31 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify as an acute angle (less than 90 degrees)", () => {
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 as an obtuse angle (greater then 90 degrees and less then 180 degrees)", () => {
expect(getAngleType(90.38)).toEqual("Obtuse angle");
expect(getAngleType(179.99)).toEqual("Obtuse angle");
expect(getAngleType(139)).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 as a straight angle (exactly 180 degrees)", () => {
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 as a reflex angle (greater than 180 degrees and less than 360 degrees)", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359.99)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
});
2 changes: 1 addition & 1 deletion Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Copy link
Contributor

Choose a reason for hiding this comment

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

In mathematics, -4/7 == 4/-7, and -4/-7 == 4/7.
So, ideally isProperFraction() should recognise all of them as proper fractions.

Similarly, -5/2 == 5/-2, and -5/-2 == 5/2.
So isProperFraction(-5, 2) should also return false because -5/2 is not a proper fraction. (Currently your function return true)

Hint: we can compare the absolute value of both parameters instead.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
else return false; // returns false if numerator is not less than denominator
}

module.exports = isProperFraction;
9 changes: 9 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 @@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
test("should return false for a improper faction", () => {
expect(isProperFraction(5, 2)).toEqual(false);
});

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for a equal fraction", () => {
expect(isProperFraction(3, 3)).toEqual(false);
})
21 changes: 19 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,22 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character)
if (rank === "A") return 11; // this checks for Aces
// Handle Number Cards (2-9)
if (rank === "2") return 2; // this checks for the twos
if (rank === "3") return 3; // this checks for the threes
if (rank === "4") return 4; // this checks for the fours
if (rank === "5") return 5; // this should check for fives
if (rank === "6") return 6; // this checks for the sixes
if (rank === "7") return 7; // this checks for the sevens
if (rank === "8") return 8; // this checks for the eights
if (rank === "9") return 9; // this checks for the nines
// Handle Face Cards (J, Q, K) And 10's
if (rank === "J") return 10; // this checks for Jacks
if (rank === "Q") return 10; // this checks for Queens
if (rank === "K") return 10; // this checks for Kings
if (rank === "10") return 10; // this checks for Tens
// if none of the above its an invalid card and throw an error
throw new Error("Invalid card rank."); // this will throw an error if the card is not a valid rank
}

module.exports = getCardValue;
23 changes: 23 additions & 0 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):
test("should return the correct value for number cards between 2 and 9", () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("3♦")).toEqual(3);
expect(getCardValue("4♣")).toEqual(4);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("6♥")).toEqual(6);
expect(getCardValue("7♦")).toEqual(7);
expect(getCardValue("8♣")).toEqual(8);
expect(getCardValue("9♠")).toEqual(9);
expect(getCardValue("10♥")).toEqual(10);
});
// 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 Aces", () => {
expect(getCardValue("A♠")).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should throw an error for invalid card ranks", () => {
expect(() => getCardValue("X♠")).toThrow("Invalid card rank.");
expect(() => getCardValue("1♠")).toThrow("Invalid card rank.");
})
15 changes: 14 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
// start a count of 0
let count = 0;

// check each of the characters in the string one by one.
for (let i = 0; i < stringOfCharacters.length; i++) {
// checks if the current characters matches the one were looking for in the string.
if (stringOfCharacters[i] === findCharacter)
// if it does, we increment the count by 1.
count = count + 1;
}

return count;
}
console.log(countChar("aaaaa", "a")); // 5
console.log(countChar("hello", "l")); // 2

module.exports = countChar;
7 changes: 7 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,10 @@ 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 for no occurrences of a character", () => {
const str = "example";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});
24 changes: 23 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,27 @@
function getOrdinalNumber(num) {
return "1st";
const lastTwoDigits = num % 100; // gets the last two digits of the number because some like 11, 12, 13 are special cases.
const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd"

// handles special cases "11, 12 ,13" to always end in "Th".
if(lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){
return num + "th";
}

// will return "St" if the number ends in 1.
if (lastDigit === 1){
return num + "st";
}
// will return "Nd" if the number ends in 2.
if (lastDigit === 2){
return num + "nd";
}
// will return "Rd" if the number ends in 3.
if (lastDigit === 3){
return num + "rd";
}

// will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th".
return num + "th";
}

module.exports = getOrdinalNumber;
39 changes: 37 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,43 @@ const getOrdinalNumber = require("./get-ordinal-number");

// Case 1: Identify the ordinal number for 1
// When the number is 1,
// Then the function should return "1st"
// Then the function should return ordinal numbers what end with the "1st"

test("should return '1st' for 1", () => {
test("should return '1st' for ordinal numbers ending in 1 like (1, 21, 31..)", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(31)).toEqual("31st")
});

// Case 2: Identify the ordinal number for 2
// When the number is 2,
// The function should then return ordinal numbers what end with the "2nd".

test("Should return `2nd` for ordinal numbers ending in 2 like (2, 22, 32...)", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(32)).toEqual("32nd");
});

// Case 3: Identify the ordinal number for 3
// When the number is 3,
// The Function should return the ordinal numbers what finish with the "3rd"

test("Should return `3rd` for ordinal numbers ending in 3 like (3, 23, 33...", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(33)).toEqual("33rd");
});

// Case 4: identify the special ordinal numbers for 11, 12, 13
// When the number is 11, 12, 13,
// The function should return "11th, 12th, 13th"

test ("should return `11th, 12th, 13th` for special ordinal numbers ending on these", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");
});
Loading