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 9e05a871e2..16c48e830d 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,30 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle>0 && angle<90) + { +return "Acute angle"; + } + else if (angle==90) + { + return "Right angle"; + } + else if (angle>90 && angle<180) + { + return "Obtuse angle"; + } + else if (angle==180) + { + return "Straight angle"; + } + else if (angle>180 && 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 +59,30 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(1); +assertEquals(acute,"Acute angle"); + +const obtuse = getAngleType(90.5); +assertEquals(obtuse,"Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight,"Straight angle"); + +const reflex = getAngleType(359.9); +assertEquals(reflex,"Reflex angle"); + +const invalid = getAngleType(380); +assertEquals(invalid,"Invalid angle"); + +const straight2 = getAngleType(180); +assertEquals(straight2,"Straight angle"); + +const invalid2 = getAngleType(360); +assertEquals(invalid2,"Invalid angle"); + +const acute2 = getAngleType(0.1); +assertEquals(acute2,"Acute angle"); + +const invalid3 = getAngleType(0); +assertEquals(invalid3,"Invalid angle"); \ No newline at end of file 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 970cb9b641..3fd208bf6c 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,6 +12,14 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + numerator = Math.abs(numerator); + denominator = Math.abs(denominator); + if (numerator 10)) { + throw new Error("Invalid card"); + } + + if (faceCardValues[value] !== undefined) { + return faceCardValues[value]; + } + + const numvalue = Number(value); + if (numvalue >= 2 && numvalue <= 10) { + return numvalue; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,7 +63,12 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); - +assertEquals(getCardValue("A♥"),11); +assertEquals(getCardValue("10♠"),10); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("K♠"), 10); +assertEquals(getCardValue("q♦"), 10); +assertEquals(getCardValue("J♣"), 10); // Handling invalid cards try { getCardValue("invalid"); 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 d777f348d3..5d4445b467 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,36 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (Angle ===90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(90)).toEqual("Right angle"); + +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when ( 90 < angle < 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(125)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when (angle === 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various reflex angles, including boundary cases + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => { + // Test various invalid angles + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); +}); \ No newline at end of file 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 7f087b2ba1..2e9b73fe4d 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,27 @@ 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. +test(`should return True when denominator is positive and less than numerator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true ); + expect(isProperFraction(20, 21)).toEqual(true ); + expect(isProperFraction(60, 90)).toEqual(true ); +}); + +test(`should return false when denominator greater than numerator`, () => { + expect(isProperFraction(10, 1)).toEqual(false); + expect(isProperFraction(11, 1)).toEqual(false); +}); + +test(`should return false when denominator and numerators are Equal`, () => { + expect(isProperFraction(1, 1)).toEqual(false); + expect(isProperFraction(-1,-1)).toEqual(false); + expect(isProperFraction(-1, 1)).toEqual(false); +}); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(-1, 0)).toEqual(false); + expect(isProperFraction(0, 0)).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 cf7f9dae2e..e24d5902c3 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 @@ -11,8 +11,34 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +test(`Should return 10 when given a number card`, () => { + 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); +}); // Face Cards (J, Q, K) +test(`Should return 10 when given a number card`, () => { + expect(getCardValue("K♠")).toEqual(10); + expect(getCardValue("q♦")).toEqual(10); + expect(getCardValue("J♣")).toEqual(10); +}); + // Invalid Cards +test(`Should return Invalid Cards when given invalid inputs`, () => { + expect(() => getCardValue("")).toThrow(); + expect(() => getCardValue("11")).toThrow(); + expect(() => getCardValue("♠10")).toThrow(); + expect(() => getCardValue("invalid")).toThrow(); + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("ab")).toThrow(); + +}); // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: diff --git a/package.json b/package.json index 0657e22dd8..b663c628f2 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "dependencies": { + "devDependencies": { "jest": "^29.7.0" } -} \ No newline at end of file +}