Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
32eef26
implemented acute and obtuse angle identification in getAngleType fun…
CatchingKiyoko Nov 1, 2025
0709cbe
Implement straight angle identification in getAngleType function and …
CatchingKiyoko Nov 1, 2025
def5669
fixed if statement for obtuse angle
CatchingKiyoko Nov 1, 2025
487694e
Implement reflex angle identification in getAngleType function and ad…
CatchingKiyoko Nov 1, 2025
5fb6f95
fix: add missing assertions for negative and equal fraction checks
CatchingKiyoko Nov 1, 2025
876b8a1
Implement card value retrieval for face cards and number cards in get…
CatchingKiyoko Nov 1, 2025
801d5d8
Implement numerical value retrieval for cards 2-9 in getCardValue fun…
CatchingKiyoko Nov 1, 2025
7e6166b
Enhance getCardValue function comments and add error handling for inv…
CatchingKiyoko Nov 1, 2025
dbf085f
Fix typo in error message assertion for invalid card rank in getCardV…
CatchingKiyoko Nov 1, 2025
a09a992
refactor: implement character counting logic in countChar function
CatchingKiyoko Nov 1, 2025
5f2aa2c
add test for handling no occurrences of a character in countChar func…
CatchingKiyoko Nov 1, 2025
22f8e4a
implemented how special ordinal number cases like 11,12,13 are handle…
CatchingKiyoko Nov 1, 2025
f3f8b47
refactor: implement getOrdinalNumber function to return correct ordin…
CatchingKiyoko Nov 1, 2025
f08ec15
implented tests for ordinal numbers 2nd and 3rd
CatchingKiyoko Nov 1, 2025
234e8b6
test: update test descriptions for ordinal numbers and implemented a …
CatchingKiyoko Nov 1, 2025
6a021e3
implemented repeat function with error handling and edge cases with c…
CatchingKiyoko Nov 1, 2025
7455253
test: add test case for returning original string when count is 1
CatchingKiyoko Nov 1, 2025
5e1196f
test: add test case for returning original string when count is 0
CatchingKiyoko Nov 1, 2025
cc80d7e
test: add test case for returning original string when count is negative
CatchingKiyoko Nov 1, 2025
ca08ca9
implemented the cases of jest tests for each of the angles
CatchingKiyoko Nov 15, 2025
7dc44ec
fix: update isProperFraction function logic and add missing assertion
CatchingKiyoko Nov 15, 2025
5e720c8
fix: update isProperFraction to return false for zero denominator ins…
CatchingKiyoko Nov 15, 2025
252bfb9
added "module.exports" so jest can find the function
CatchingKiyoko Nov 15, 2025
3b7e322
implmented jest tests for each of the cases
CatchingKiyoko Nov 15, 2025
809e11b
fixed equal numerator and denominator jest test
CatchingKiyoko Nov 15, 2025
0b2a485
added module.exports
CatchingKiyoko Nov 15, 2025
377b7db
fix: clean up formatting and ensure consistent error handling in getC…
CatchingKiyoko Nov 15, 2025
096d45c
fix: correct ordinal suffix for special cases in getOrdinalNumber fun…
CatchingKiyoko Nov 15, 2025
1200ba7
fix: enhance tests for getOrdinalNumber function to cover additional …
CatchingKiyoko Nov 15, 2025
014b90e
Enhance tests for proper fraction validation
CatchingKiyoko Nov 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
// 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 === 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";

// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.
}
Expand Down Expand Up @@ -50,14 +53,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");
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
// 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 (denominator === 0) return false; // avoid division by zero
return Math.abs(numerator) < Math.abs(denominator);
Comment on lines +11 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.

There is no "division by zero" needs to be prevented though.

Will the function still work equally well without this if statement?

Copy link
Author

Choose a reason for hiding this comment

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

yes it would still work because it would return false implicitly with out the if-statement, as im currently explicitly looking for the error having the if-statement in.

}

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
Expand Down Expand Up @@ -47,13 +42,17 @@ 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?

module.exports = isProperFraction;
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +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
}

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;

// 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 @@ -38,20 +48,38 @@ 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.");
}
module.exports = getCardValue;
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ 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 Acute angle (< 90°)", () => {
expect(getAngleType(75)).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 Obtuse angle (> 90° and < 180°)", () => {
expect(getAngleType(155)).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 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 as Reflex angle (> 180° and < 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => {
});

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

// Case 3: Identify Negative Fractions:
test("should return true for a negative proper fraction", () => {
expect(isproperFraction(-4, 7)).toEqual(true);
});
Comment on lines +15 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

Could consider introduce a test for negative improper fraction to make the test more complete.

Copy link
Author

Choose a reason for hiding this comment

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

have implemented the test for negative improper fractions.


// Case 4: Identify Equal Numerator and Denominator:
test ("should return false when numerator equals denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@ test("should return 11 for Ace of Spades", () => {
expect(aceofSpades).toEqual(11);
});

// 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.");
});
17 changes: 15 additions & 2 deletions Sprint-3/2-practice-tdd/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;
module.exports = countChar;
7 changes: 7 additions & 0 deletions Sprint-3/2-practice-tdd/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);
});
23 changes: 22 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
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 like "11,12,13" to always end in the "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;
33 changes: 33 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,37 @@ const getOrdinalNumber = require("./get-ordinal-number");

test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st")
expect(getOrdinalNumber(141)).toEqual("141st")
});
// Case 2: Identify the ordinal number for 2
// When the number is 2,
// The function should then return "2nd".

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(132)).toEqual("132nd");
});

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

test("Should return `3rd` for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(133)).toEqual("133rd");
});
// 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");
});
18 changes: 16 additions & 2 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function repeatStr() {
return "hellohellohello";
function repeatStr(str, count) {
// check if "count" is a negative number if so will throw new error
if (count < 0) {
throw new error("Count must be a positive number");

//check if the is equal to zero
if (count === 0){
return ""; // returns empty string if count is equal to zero
}
//check if the count is equals 1.
if (count === 1) {
//returns just the string as its not needed to be repeated
return str;
}
return str.repeat(count); // if the count is above two it repeat "count" number of times.
}
}

module.exports = repeatStr;
17 changes: 17 additions & 0 deletions Sprint-3/2-practice-tdd/repeat-str.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,30 @@ test("should repeat the string count times", () => {
// Given a target string str and a count equal to 1,
// When the repeatStr 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 when count is 1", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hello");
});

// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeatStr 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 give a empty string when count is 0", () => {
const str = "hello";
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 repeatStr 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 when count is negative", () => {
const str = "hello"
const count = -1;
expect(() => repeat(str,count)).toThrow("Count must be a positive number");
});