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..1c585face 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 @@ -16,6 +16,12 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90) return "Acute angle"; + else if (angle === 90) return "Right angle"; + else if (90 < angle && angle < 180) return "Obtuse angle"; + else if (angle === 180) return "Straight angle"; + else if (180 < angle && angle < 360) return "Reflex angle"; + else return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +41,31 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); +let acute = getAngleType(1); +assertEquals(acute, "Acute angle"); +acute = getAngleType(45); +assertEquals(acute, "Acute angle"); +acute = getAngleType(89); +assertEquals(acute, "Acute angle"); +let obtuse = getAngleType(91); +assertEquals(obtuse, "Obtuse angle"); +obtuse = getAngleType(100); +assertEquals(obtuse, "Obtuse angle"); +obtuse = getAngleType(179); +assertEquals(obtuse, "Obtuse angle"); +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); +let reflex = getAngleType(200); +assertEquals(reflex, "Reflex angle"); +reflex = getAngleType(243); +assertEquals(reflex, "Reflex angle"); +reflex = getAngleType(359); +assertEquals(reflex, "Reflex angle"); +let invalid = getAngleType(-11); +assertEquals(invalid, "Invalid angle"); +invalid = getAngleType(0); +assertEquals(invalid, "Invalid angle"); +invalid = getAngleType(360); +assertEquals(invalid, "Invalid angle"); +invalid = getAngleType(371); +assertEquals(invalid, "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..c44147e38 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 @@ -12,8 +12,9 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (Math.abs(numerator) < Math.abs(denominator)) return true; + else return false; } - // 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; @@ -31,3 +32,9 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(7, 4), false); +assertEquals(isProperFraction(-8, 5), false); +assertEquals(isProperFraction(9, 10), true); +assertEquals(isProperFraction(-3, -6), true); +assertEquals(isProperFraction(15, 11), false); +assertEquals(isProperFraction(-17, -24), 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..72bb51847 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 @@ -20,11 +20,42 @@ // Acceptance criteria: // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. - function getCardValue(card) { // TODO: Implement this function + if (!card || typeof card !== "string") { + throw new Error("Invalid card"); + } + // + const validSuits = ["♠", "♥", "♦", "♣"]; + const suit = card.slice(-1); //takes the last character of the string. + const rank = card.slice(0, -1); //takes everything except the last character. + + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); // This if statement checks the suit is valid with the Array of suit we assigned + } + // Based on the question i get form mentor i changed the function if statement for better experience of the code. + const cardValues = { + A: 11, + J: 10, + Q: 10, + K: 10, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + 7: 7, + 8: 8, + 9: 9, + 10: 10, + }; // This is java script object that act as like lookup table for the valid card value input. + + if (cardValues[rank] !== undefined) return cardValues[rank]; + throw new Error("Invalid card"); } +module.exports = getCardValue; + // 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; 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..b06ce6260 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 @@ -6,15 +6,41 @@ const getAngleType = require("../implement/1-get-angle-type"); // including boundary and invalid cases. // Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { +test(`should return "Acute angles" when (0 < angle < 90)`, () => { // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(1)).toBe("Acute angle"); + expect(getAngleType(45)).toBe("Acute angle"); + expect(getAngleType(89)).toBe("Acute angle"); }); - // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(90)).toBe("Right angle"); +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(97)).toBe("Obtuse angle"); + expect(getAngleType(129)).toBe("Obtuse angle"); + expect(getAngleType(165)).toBe("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when (angle ==180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(180)).toBe("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angles" when (180 < angle < 360)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(191)).toBe("Reflex angle"); + expect(getAngleType(250)).toBe("Reflex angle"); + expect(getAngleType(317)).toBe("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angles" when (angle >= 360 or angle<= 0 )`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(0)).toBe("Invalid angle"); + expect(getAngleType(-45)).toBe("Invalid angle"); + expect(getAngleType(370)).toBe("Invalid angle"); + expect(getAngleType(360)).toBe("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..3bdc841d8 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 @@ -3,8 +3,25 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. - // Special case: numerator is zero test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(-11, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); + expect(isProperFraction(7, 0)).toEqual(false); +}); +// It should return false when the numerator > the denominator +test("should return true when numerator is 0", () => { + expect(isProperFraction(0, -1)).toEqual(true); + expect(isProperFraction(0, 3)).toEqual(true); + expect(isProperFraction(0, -2)).toEqual(true); +}); +test("should return true when numerator > denominator", () => { + expect(isProperFraction(-12, -19)).toEqual(true); + expect(isProperFraction(0, 6)).toEqual(true); + expect(isProperFraction(17, -71)).toEqual(true); +}); +test("should return false when numerator < denominator", () => { + expect(isProperFraction(-180, -109)).toEqual(false); + expect(isProperFraction(27, 5)).toEqual(false); + expect(isProperFraction(-29, 17)).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..b9ec76397 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 @@ -8,7 +8,29 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); - +// Case 2: Number Cards (2-10) +test(`Should return the numeric value for number cards`, () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("9♦")).toEqual(9); + expect(getCardValue("10♣")).toEqual(10); +}); +// Case 3: 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: Invalid Cards +test(`Should throw "Invalid card" for invalid cards`, () => { + expect(() => getCardValue("1♠")).toThrow("Invalid card"); + expect(() => getCardValue("B♠")).toThrow("Invalid card"); + expect(() => getCardValue("A$")).toThrow("Invalid card"); + expect(() => getCardValue("10X")).toThrow("Invalid card"); + expect(() => getCardValue("0x02♠")).toThrow("Invalid card"); + expect(() => getCardValue("2.1♠")).toThrow("Invalid card"); + expect(() => getCardValue("0002♠")).toThrow("Invalid card"); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) @@ -17,4 +39,3 @@ test(`Should return 11 when given an ace card`, () => { // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror -