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..76fdf82db 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,24 @@ 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 +53,13 @@ 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 (110); +assertEquals(obtuse, "Obtuse angle"); +const straight = getAngleType (180); +assertEquals(straight, "Straight angle"); +const reflex = getAngleType (270); +assertEquals(reflex, "Reflex angle"); +const invalid = getAngleType (400); +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..dcb1f2a6f 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,10 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (numerator > 0 && denominator > 0 && numerator < denominator) { + return true; + } + else return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(2,1),false); +assertEquals(isProperFraction(1,1),false); +assertEquals(isProperFraction(0,1),false); +assertEquals(isProperFraction(1,-2),false); +assertEquals(isProperFraction(-1,2),false); 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..60f9ac75b 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 @@ -23,6 +23,44 @@ function getCardValue(card) { // TODO: Implement this function + if (card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣") { + return 11; + } + else if (card === "J♠" || card === "J♥" || card === "J♦" || card === "J♣" || + card === "Q♠" || card === "Q♥" || card === "Q♦" || card === "Q♣" || + card === "K♠" || card === "K♥" || card === "K♦" || card === "K♣") { + return 10; + } + else if (card === "2♠" || card === "2♥" || card === "2♦" || card === "2♣") { + return 2; + } + else if (card === "3♠" || card === "3♥" || card === "3♦" || card === "3♣") { + return 3; + } + else if (card === "4♠" || card === "4♥" || card === "4♦" || card === "4♣") { + return 4; + } + else if (card === "5♠" || card === "5♥" || card === "5♦" || card === "5♣") { + return 5; + } + else if (card === "6♠" || card === "6♥" || card === "6♦" || card === "6♣") { + return 6; + } + else if (card === "7♠" || card === "7♥" || card === "7♦" || card === "7♣") { + return 7; + } + else if (card === "8♠" || card === "8♥" || card === "8♦" || card === "8♣") { + return 8; + } + else if (card === "9♠" || card === "9♥" || card === "9♦" || card === "9♣") { + return 9; + } + else if (card === "10♠" || card === "10♥" || card === "10♦" || card === "10♣") { + return 10; + } + else { + throw new Error("Invalid card"); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +78,9 @@ 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("J♦"), 10); +assertEquals(getCardValue("10♣"), 10); // Handling invalid cards try { @@ -50,3 +91,7 @@ try { } catch (e) {} // What other invalid card cases can you think of? +try { + getCardValue("1♠"); +console.error("Error was not thrown for invalid card");} +catch (e) {} \ No newline at end of file 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..0dee2734e 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,30 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is exactly 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +} +); // Case 4: Straight angle +test(`should return "Straight angle" when angle is exactly 180`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + 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 is outside the valid range`, () => { + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(400)).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..7e85c2ba1 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,27 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +test('should return false when numerator is zero', () => { + expect(isProperFraction(0, 1)).toEqual(false); +}); +test('should return false when both numerator and denominator are zero', () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); +test('should return false when numerator is negative', () => { + expect(isProperFraction(-1, 2)).toEqual(false); +}); +test('should return false when denominator is negative', () => { + expect(isProperFraction(1, -2)).toEqual(false); +}); +test('should return false when both numerator and denominator are negative', () => { + expect(isProperFraction(-1, -2)).toEqual(false); +}); +test('should return true if numerator is less than denominator and both are positive', () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); +test('should return false if numerator is greater than denominator and both are positive', () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); +test('should return false if numerator is equal to denominator and both are positive', () => { + expect(isProperFraction(1, 1)).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..926e6badc 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,6 +8,27 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +test(`Should return 10 when given a face card`, () => { + expect(getCardValue("J♦")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); +}); +test(`Should return the numeric value 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); +}); +test ('Should return invalid card error when given invalid cards', () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("11♥")).toThrow(); +}); + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10)