diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e..319f7380f 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,8 +15,15 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (typeof angle !== "number" || angle <= 0 || angle >= 360) + return "Invalid 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"; + return "Reflex angle"; } +console.log(); // The line below allows us to load the getAngleType function into tests in other files. // This will be useful in the "rewrite tests with jest" step. @@ -35,3 +42,21 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(260); +assertEquals(reflex, "Reflex angle"); + +const invalid1 = getAngleType(400); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType("400"); +assertEquals(invalid2, "Invalid angle"); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b64..9f64b7f37 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,7 +11,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + numerator = Math.abs(numerator); + denominator = Math.abs(denominator); + if (numerator < denominator) return true; + else if (numerator > denominator) return false; + else if (numerator === denominator) return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Example: 5/2 is not a proper fraction +const improperFraction = isProperFraction(5, 2); +assertEquals(improperFraction, false); + +// Example: -4/7 is a proper fraction +const negativeFraction = isProperFraction(-4, 7); +assertEquals(negativeFraction, true); + +// Example: 3/3 is not a proper fraction +const equalFraction = isProperFraction(3, 3); +assertEquals(equalFraction, false); + +// Example: 4/-7 is a proper fraction +const negativeFraction1 = isProperFraction(4, -7); +assertEquals(negativeFraction1, true); + +// Example: -4/-7 is a proper fraction +const negativeFraction2 = isProperFraction(4, 7); +assertEquals(negativeFraction2, true); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index c7559e787..5c1c8aa65 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,7 +22,14 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if (!["♠", "♣", "♦", "♥"].includes(card.slice(-1))) + throw new Error("Invalid card rank."); + const rank = card.slice(0, card.length - 1); + if (rank === "A") return 11; + if (["10", "J", "Q", "K"].includes(rank)) return 10; + if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) + return Number(rank); + throw new Error("Invalid card rank."); } // The line below allows us to load the getCardValue function into tests in other files. @@ -50,3 +57,11 @@ try { } catch (e) {} // What other invalid card cases can you think of? +const fiveOfHearts = getCardValue("5♥"); +assertEquals(fiveOfHearts, 5); + +const faceCard = getCardValue("J♣"); +assertEquals(faceCard, 10); + +const aceCard = getCardValue("A♦"); +assertEquals(aceCard, 11); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d..c0fb38250 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -14,7 +14,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Acute angle" when (angle = 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test("should identify obtuse angle (90° < angle < 180°)", () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(130)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test("should identify straight angle (angle = 180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test("should identify reflex angle (180° < angle < 360)", () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(280)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test("should identify invalid angle (0 > angle > 360)", () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba..f8e06e4ae 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// Case 2: Identify Improper Fractions: +test("should return false for improper fraction", () => { + expect(isProperFraction(2, 3)).toEqual(true); +}); + +// Case 3: Identify Negative Fractions: +test("should return true for proper negative fraction", () => { + expect(isProperFraction(-3, 6)).toEqual(true); +}); +test("should return false for improper negative fraction", () => { + expect(isProperFraction(-5, 2)).toEqual(false); +}); + +// Case 4: Identify Equal Numerator and Denominator: +test("should return false for improper fraction (numerator === denominator)", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2..6fad6ddee 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -18,3 +18,32 @@ test(`Should return 11 when given an ace card`, () => { // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror +// Case 2: Handle Number Cards (2-10): +test("should return the appropriate number from 2 to 10", () => { + 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", () => { + 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 (A)", () => { + expect(getCardValue("A♣")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); + expect(getCardValue("A♥")).toEqual(11); +}); +// Case 5: Handle Invalid Cards: +test("Should return 'Invalid card rank.' for invalid cards", () => { + expect(() => getCardValue("KJ")).toThrow("Invalid card rank."); + expect(() => getCardValue("AK")).toThrow("Invalid card rank."); +});