From dad46f3e6c0b31c2b65dd2495be295ca32c2da06 Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 16:58:42 +0100 Subject: [PATCH 1/6] rewrite code completely and tests --- .../implement/1-get-angle-type.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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..45ab59e6dd 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,8 +16,34 @@ function getAngleType(angle) { // TODO: Implement this function + // first converting conditions into variables + const acuteAngle = (angle > 0 && angle < 90); + const rightAngle = (angle === 90); + const obtuseAngle = (angle > 90 && angle < 180); + const straightAngle = (angle === 180); + const reflexAngle = (angle > 180 && angle < 360); + const zeroAngle = (angle === 0); + + + if (rightAngle) { + // checking for conditions + return "Right angle"; + } else if (zeroAngle) { + return "Invalid angle"; + }else if (obtuseAngle) { + return "Obtuse angle"; + } else if (straightAngle) { + return "Straight angle"; + } else if (reflexAngle) { + return "Reflex angle"; + } else if (acuteAngle) { + return "Acute angle"; + } else if (angle === zeroAngle || angle != acuteAngle || angle != rightAngle || angle != obtuseAngle || angle != straightAngle || angle != reflexAngle) { + return "Invalid angle"; + } } + // 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. module.exports = getAngleType; @@ -35,3 +61,24 @@ 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(270); +assertEquals(reflex, "Reflex angle"); + +const invalidAngle1 = getAngleType(360); +assertEquals(invalidAngle1, "Invalid angle"); + +const invalidAngle2 = getAngleType(0); +assertEquals(invalidAngle2, "Invalid angle"); + +const invalidAngle3 = getAngleType(-1); +assertEquals(invalidAngle3, "Invalid angle"); \ No newline at end of file From aca3a783ba992e60307a2cc262c70bc6c41c0809 Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 17:07:08 +0100 Subject: [PATCH 2/6] rewrite code and tests --- .../implement/2-is-proper-fraction.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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..faa27ba337 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,9 +11,14 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (Math.abs(numerator / denominator) < 1) { + return true;// if numerator is smaller than denominator - return true + } else { + return false;//return false if numerator if bigger that denominator + } } + // 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 +36,12 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Example: 2/3 is a proper fraction +assertEquals(isProperFraction(2, 3), true); + +// Example: 4/2 is not a proper fraction +assertEquals(isProperFraction(4, 2), false); + +// Example: 4/4 is not a proper fraction +assertEquals(isProperFraction(4, 4), false); \ No newline at end of file From 98ad527bf771d20dd9cdf594b64cb490ffdfc80b Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 17:10:09 +0100 Subject: [PATCH 3/6] rewrite code and tests --- .../implement/3-get-card-value.js | 131 +++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) 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 ff5c532e1d..d0167067ca 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,41 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suit = ["♠", "♥", "♦", "♣"]; // array with suits + const rank = [ + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "A", + "K", + "Q", + "J", + ]; // array with ranks + const tenPointsFaceCards = ["K", "Q", "J"]; //cards with value of 10 points + + const rank1 = card.slice(0, -1); //takes the firs part of card + const suit1 = card.slice(-1); //takes "suit" secnd part of card + const isCardValid = suit.includes(suit1) && rank.includes(rank1); //conditions where card is considered valid + + //conditional statement to check validity of the card + if (!isCardValid) { + throw new Error("Invalid card format"); + } + + //conditional statements to check what value to return depending on the card value + if (rank1 === "A") { + return 11; + } else if (tenPointsFaceCards.includes(rank1)) { + return 10; + } else { + return Number(rank1); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -39,8 +73,23 @@ 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("K♠"), 10); + +assertEquals(getCardValue("Q♠"), 10); + +assertEquals(getCardValue("J♠"), 10); + +assertEquals(getCardValue("10♣"), 10); + +//assertEquals(getCardValue("11♣"), "Invalid card format"); i find that +// this test will not work, because my function is throwing error before the program +// reaches the assertEquals function. + // Handling invalid cards try { getCardValue("invalid"); @@ -52,3 +101,83 @@ try { } // What other invalid card cases can you think of? +try { + getCardValue("11♣"); // testing with "11♣" the error will be thrown because "11" is not a valid rank + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("A"); // testing with "A" the error will be thrown because there is no suit + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("10"); // testing with "10" the error will be thrown because there is no suit + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("1♣"); // testing with "1♣" the error will be thrown because "1" is not a valid rank + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("A5"); // testing with "A5" the error will be thrown because "5" is not a valid suit + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("♣6"); // testing with "♣6" the error will be thrown because "6" is not a valid suit and "♣" is not a valid rank + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("@@"); // testing with "@@" the error will be thrown because "@" is not a valid rank or suit + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("-6♣"); // testing with "-6♣" (negative number) the error will be thrown because "-" is not a valid rank + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue(""); // testing with "" the error will be thrown because "" is not a valid card + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} \ No newline at end of file From 4d82fed58cee6ac3098830448ee65dd12baad608 Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 17:14:22 +0100 Subject: [PATCH 4/6] rewrite code and tests --- .../1-get-angle-type.test.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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..20e87d9695 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 @@ -10,11 +10,43 @@ test(`should return "Acute angle" 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(89.9)).toEqual("Acute angle"); }); // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + //test right angle at 90 degrees + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 > angle > 180)`, () => { + //test various obtuse cases, including border cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179.9)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when (angle ==== 180)`, () => { + //test for straight angle at 180 degrees + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 > angle > 360)`, () => { + //test for various reflex angle between 181 and 359 degrees + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(210)).toEqual("Reflex angle"); + expect(getAngleType(359.9)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle >= 0 || angle >= 360 || angle === isNan())`, () => { + //tests for various invalid angles + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(380)).toEqual("Invalid angle"); + expect(getAngleType(NaN)).toEqual("Invalid angle"); +}); + + From 49eff3b06b0c9730c41cfc1f278e31728349aad8 Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 17:15:54 +0100 Subject: [PATCH 5/6] rewrite code and tests --- .../2-is-proper-fraction.test.js | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) 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..418d5f587f 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,62 @@ 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); }); + +// Special case: numerator is zero +test(`should return true when numerator is zero `, () => { + expect(isProperFraction(0, 2)).toEqual(true); +}); + +// numerator and denominator are both zero +test(`should return false when numerator and denominator are both zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); + +// negative numerator and positive denominator +test(`should return true when numerator is negative and denominator is positive`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); +}); + +// positive numerator, negative denominator +test(` should return false when numerator is positive and denominator is negative`, () => { + expect(isProperFraction(1, -2)).toEqual(true); +}) + +//negative numerator and denominator where numerator is smaller than denominator +test(`should return true when numerator is negative and denominator is negative and numerator is smaller than denominator`, () => { + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +//negative numerator and denominator where numerator is bigger than denominator +test(`should return false when numerator is negative and denominator is negative and numerator is bigger than denominator`, () => { + expect(isProperFraction(-2, -1)).toEqual(false); +}); + +//positive numerator and denominator where numerator is smaller +test(`should return true when numerator is smaller`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +// positive numerator and denominator, numerator is larger +test(`should return false when numerator is larger`, () => { + expect(isProperFraction(4, 2)).toEqual(false); +}); + +// equal numerator and denominator +test(`should return false when numerator and denominator are equal`, () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); + +// numerator and denominator are both floating point numbers, numerator is smaller +test(`should return true when numerator and denominator are both floating point numbers and numerator is smaller`, () => { + expect(isProperFraction(1.5, 2.5)).toEqual(true); +}); + +// numerator and denominator are both floating point numbers, numerator is larger +test(`should return false when numerator and denominator are both floating point numbers and numerator is larger`, () => { + expect(isProperFraction(2.5, 1.5)).toEqual(false); +}); \ No newline at end of file From 13eba78603e0aa2c851b2fd2fc879b1a1270bb06 Mon Sep 17 00:00:00 2001 From: vmoratti Date: Fri, 17 Jul 2026 17:18:39 +0100 Subject: [PATCH 6/6] rewrite tests and code --- .../3-get-card-value.test.js | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) 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..92c8da24b4 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 @@ -3,18 +3,58 @@ const getCardValue = require("../implement/3-get-card-value"); // TODO: Write tests in Jest syntax to cover all possible outcomes. +// Suggestion: Group the remaining test data into these categories: +// Number Cards (2-10) +// Face Cards (J, Q, K) +// Invalid Cards // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Case 2: Number cards (2-9) +test(`Should return corresponding number 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); +}); +// Case 3: Number cards (10) +test(`Should return 10 when given a 10 card`, () => { + expect(getCardValue("10♠")).toEqual(10); +}); + +// Case 4: Face cards (J, Q, K) +test(`Should return 10 when given a J card`, () => { + expect(getCardValue("J♠")).toEqual(10); +}); + +// Case 5: Face cards (J, Q, K) +test(`Should return 10 when given a Q card`, () => { + expect(getCardValue("Q♠")).toEqual(10); +}); + +// Case 6: Face cards (J, Q, K) +test(`Should return 10 when given a K card`, () => { + expect(getCardValue("K♠")).toEqual(10); +}); + +// Invalid cases +test(`should throw an error with message "Invalid card format" when given invalid card`, () => { + expect(() => getCardValue("1♠")).toThrow("Invalid card format"); + expect(() => getCardValue("11♥")).toThrow("Invalid card format"); + expect(() => getCardValue("A1")).toThrow("Invalid card format"); + expect(() => getCardValue("1A")).toThrow("Invalid card format"); + expect(() => getCardValue("♣10")).toThrow("Invalid card format"); + expect(() => getCardValue("$$")).toThrow("Invalid card format"); + expect(() => getCardValue("-5♣")).toThrow("Invalid card format"); +}); // 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 - +// https://jestjs.io/docs/expect#tothrowerror \ No newline at end of file