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..417ad70afe 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,7 +15,14 @@ // 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 "Acute angle"; + if (angle === 90) return "Right angle"; + if (angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle < 360) return "Reflex angle"; + if (angle === 360) return "Full rotation angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +42,33 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Case 2: Identify Acute Angles: +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +const angle1=getAngleType(89) +assertEquals(angle1, "Acute angle"); + +const angle2=getAngleType(-45) +assertEquals(angle2, "Invalid angle"); + +// Case 3: Identify Obtuse Angles: +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Case 4: Identify Straight Angles: +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Case 5: Identify Reflex Angles: +const reflex = getAngleType(300); +assertEquals(reflex, "Reflex angle"); + +//case 6: Identify Invalid angle: +assertEquals(getAngleType(367),"Invalid angle"); + +//case 7: Identify boundary angle: +assertEquals(getAngleType(1), "Acute angle"); + +assertEquals(getAngleType(0), "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..ca28df1117 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,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + return Math.abs(numerator) < Math.abs(denominator) } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +31,27 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +//Case 2: 5/5 is not a proper fraction +assertEquals(isProperFraction(5,5), false); + +//Case 3: (-3)/(-5) is a proper fraction +assertEquals(isProperFraction(-3,-5), true); + +//Case 4: (-4)/6 is a proper fraction +assertEquals(isProperFraction(-4,6),true); + +//case 5: 5/(-8) is a proper fraction +assertEquals(isProperFraction(5,-8), true); + +//case 6: 9/7 is not a proper fraction +assertEquals(isProperFraction(9,7), false); + +//case 7: 7/0 is not a proper fraction +assertEquals(isProperFraction(7,0), false); + +//case 8: 0/6 is a proper fraction +assertEquals(isProperFraction(0,6), true); + +//case 9: 0/-8 is a proper fraction +assertEquals(isProperFraction(0,-8), true); \ No newline at end of file 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 c7559e787e..0bf4daff44 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,8 +22,23 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + + if (!validSuits.includes(suit) || !validRanks.includes(rank)) { + throw new Error("Invalid card"); + } + + if (rank === "A") return 11; + if (["J", "Q", "K"].includes(rank)) return 10; + + return Number(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. @@ -38,15 +53,45 @@ function assertEquals(actualOutput, targetOutput) { } // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: +// Examples 1 numbers: +// Examples 1 numbers: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("5♣"), 5); + +//Examples A: +assertEquals(getCardValue("A♦"), 11) -// Handling invalid cards -try { - getCardValue("invalid"); +//Examples J Q K:, +assertEquals(getCardValue("Q♣"), 10) +assertEquals(getCardValue("K♠"), 10) +assertEquals(getCardValue("J♣"), 10) + +//Examples invalid numbers: +assertThrow(()=>getCardValue("1♥")) +assertThrow(()=>getCardValue("11♥")) + +//Examples invalid suit: +assertThrow(()=>getCardValue("A*")) + +//Examples missing rank or suit: +assertThrow(()=>getCardValue("♥")) +assertThrow(()=>getCardValue("5")) + +//Example extra suit: +assertThrow(()=>getCardValue("Q♠♠")) + + +function assertThrow(fn){ +try { fn() + // we try to run this function, if it throws, stop running this bit and run the catch below // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); -} catch (e) {} +} catch (error) { + // if the above code throws, we catch the error here, that stops the whole program crashing + console.log('there was an error getting card value!',error) +}} + +console.log(' we finished running getCardValue') // What other invalid card cases can you think of? 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..0abe685612 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 @@ -12,9 +12,38 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); - + // Case 2: Right angle +test ('should return "Right angle" when angle ===90',() => { + expect(getAngleType(90)).toEqual("Right angle"); +}) // Case 3: Obtuse angles +test ('should return "Obtuse angle" when (90 { + expect(getAngleType(135)).toEqual("Obtuse angle"); +}) + // Case 4: Straight angle +test ('should return "Straight angle" when angle ===180',() => { + expect(getAngleType(180)).toEqual("Straight angle"); +}) + // Case 5: Reflex angles +test ('should return "Reflex angle" when (180 { + expect(getAngleType(275)).toEqual("Reflex angle"); +}) + // Case 6: Invalid angles + +test('should return "Full rotation angle" when (angle=360)', ()=> { + expect(getAngleType(360)).toEqual("Full rotation angle"); +}) + +test('should return "Invalid angle"when (angle>360)', ()=> { + expect(getAngleType(1012)).toEqual("Invalid angle"); +}) + + +test('should return "Invalid angle" when angle <= 0', () => { + expect(getAngleType(-5)).toEqual("Invalid angle"); + expect(getAngleType(-10)).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..f7ea08f8d6 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 @@ -4,7 +4,39 @@ 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 +/// Special case: denominator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +//case:absolute numerator is bigger than absolute denominator +test ('should return false when numerator absolute is bigger than denominator absolute',() => { + expect(isProperFraction(5, -4)).toEqual(false); + expect(isProperFraction(-5, 4)).toEqual(false); + expect(isProperFraction(-5, -4)).toEqual(false); + expect(isProperFraction(5, 4)).toEqual(false); + }); + +//case:numerator is the same as denominator +test('should return false if numerator is the same as denominator', () =>{ + expect(isProperFraction(-9,-9)).toEqual(false) + expect(isProperFraction(4,4)).toEqual(false) +}) + +//case: absolute numerator is less than absolute denominator +test ('should return true when numerator absolute is less than denominator absolute',() => { + expect(isProperFraction(3, 8)).toEqual(true); + expect(isProperFraction(-3, 8)).toEqual(true); + expect(isProperFraction(3, -8)).toEqual(true); + expect(isProperFraction(-3, -8)).toEqual(true); + }); + + +//case: numerator is zero +test(`should return true when nominator is zero`, () => { + expect(isProperFraction(0,-3)).toEqual(true); +}); + + + + 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..a9415b53c0 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 @@ -4,7 +4,7 @@ const getCardValue = require("../implement/3-get-card-value"); // TODO: Write tests in Jest syntax to cover all possible outcomes. -// Case 1: Ace (A) +// Case 1: Ace (A)1 test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); @@ -14,7 +14,23 @@ test(`Should return 11 when given an ace card`, () => { // Face Cards (J, Q, K) // Invalid Cards +// Case 2 : Number(2-10) +test('should return the exact number when given an number card', () =>{ + expect(getCardValue("5♠")).toEqual(5); +}) + +//case 3 : face card(J,Q,K) +test('should return number when given face card', () =>{ + expect(getCardValue("K♠")).toEqual(10); +}) + +// case 4: Invalid cards +test('throws new Error', () => { + expect(() => getCardValue("9**")).toThrow("Invalid 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 +