diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..31359dc48 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -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"; } diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..cace6eb38 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -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"); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..fc6fa7677 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -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; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..a5f645ce5 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -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); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..3936f908b 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -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; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..05344e87b 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -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"); +}); diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..cd28855c0 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,5 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + return str.split(char).length -1; } module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..008c28bb2 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -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); + +}); \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..da0e93c96 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -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; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..f59c1606b 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -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"); +}); \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..0fad7bc96 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -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; \ No newline at end of file +module.exports = repeat; + + diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..aec3780bf 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -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"); + });