From 0ae5f4b568265282d98375ddf342a0f4e44ef683 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:46:13 +0000 Subject: [PATCH 01/16] updated getAngleType to check for acute angle --- .../implement/1-get-angle-type.js | 3 +++ 1 file changed, 3 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 ca1dfe7f2..00987205a 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 @@ -10,6 +10,9 @@ function getAngleType(angle) { if (angle === 90) { return "Right angle"; + } + if(angle<90){ + return "Acute angle" } // Run the tests, work out what Case 2 is testing, and implement the required code here. // Then keep going for the other cases, one at a time. From dc90d4261461d7ab8503cdbc165c4909be165292 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:49:14 +0000 Subject: [PATCH 02/16] wrote test to check for obtuse angle and implemented the function to pass the test --- .../implement/1-get-angle-type.js | 4 ++++ 1 file changed, 4 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 00987205a..210c6ae47 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 @@ -13,6 +13,9 @@ function getAngleType(angle) { } if(angle<90){ return "Acute angle" + } + if(angle>90 && angle<180){ + return "Obtuse angle" } // Run the tests, work out what Case 2 is testing, and implement the required code here. // Then keep going for the other cases, one at a time. @@ -53,6 +56,7 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); +assertEquals(obtuse,"Obtuse angle") // ====> write your test here, and then add a line to pass the test in the function above // Case 4: Identify Straight Angles: From 34d3bc58f66c60974dafc0510157cc4d8b3b1360 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:51:02 +0000 Subject: [PATCH 03/16] Implement logic to identify straight angles in getAngleType function --- .../implement/1-get-angle-type.js | 5 +++++ 1 file changed, 5 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 210c6ae47..bf3759860 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,9 @@ function getAngleType(angle) { } if(angle>90 && angle<180){ return "Obtuse angle" + } + if(angle===180){ + return "Straight angle" } // Run the tests, work out what Case 2 is testing, and implement the required code here. // Then keep going for the other cases, one at a time. @@ -63,6 +66,8 @@ assertEquals(obtuse,"Obtuse angle") // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" // ====> write your test here, and then add a line to pass the test in the function above +const straight=getAngleType(180); +assertEquals(straight,"Straight angle") // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, From 023c553c33343a65587e43b44cd1852b918fe5c1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:54:22 +0000 Subject: [PATCH 04/16] Implement logic to identify reflex angles in getAngleType function --- .../implement/1-get-angle-type.js | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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 bf3759860..6d52cffbc 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 @@ -11,17 +11,20 @@ function getAngleType(angle) { if (angle === 90) { return "Right angle"; } - if(angle<90){ - return "Acute angle" + if (angle < 90) { + return "Acute angle"; } - if(angle>90 && angle<180){ - return "Obtuse angle" + if (angle > 90 && angle < 180) { + return "Obtuse angle"; } - if(angle===180){ - return "Straight angle" + if (angle === 180) { + return "Straight angle"; } - // Run the tests, work out what Case 2 is testing, and implement the required code here. - // Then keep going for the other cases, one at a time. + if(angle>180 && angle<360){ + return "Reflex angle" + } + // Run the tests, work out what Case 2 is testing, and implement the required code here. + // Then keep going for the other cases, one at a time. } // The line below allows us to load the getAngleType function into tests in other files. @@ -59,17 +62,22 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); -assertEquals(obtuse,"Obtuse angle") +assertEquals(obtuse, "Obtuse angle"); // ====> write your test here, and then add a line to pass the test in the function above // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" // ====> write your test here, and then add a line to pass the test in the function above -const straight=getAngleType(180); -assertEquals(straight,"Straight angle") +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +// ====> write your test here, and then add a line to pass the test in the function above +const reflex = getAngleType(210); +assertEquals(reflex, "Reflex angle"); + +const reflex2 = getAngleType(350); +assertEquals(reflex2, "Reflex angle"); \ No newline at end of file From c17f6c3ed41cd97f8a4c20577acda14f1d696374 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 18:02:29 +0000 Subject: [PATCH 05/16] Add tests for obtuse angles in getAngleType function --- .../implement/1-get-angle-type.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 6d52cffbc..249ee0af5 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 @@ -61,8 +61,11 @@ assertEquals(acute, "Acute angle"); // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" -const obtuse = getAngleType(120); +const obtuse = getAngleType(100); assertEquals(obtuse, "Obtuse angle"); + +const obtuse1 = getAngleType(170); +assertEquals(obtuse1, "Obtuse angle"); // ====> write your test here, and then add a line to pass the test in the function above // Case 4: Identify Straight Angles: From c5b9e5278522ffeb3c2c66f4e5587c6205cf494a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 30 Jan 2026 18:40:54 +0000 Subject: [PATCH 06/16] added additional tests to check for a properr fraction and implemented the function accordingly --- .../implement/2-is-proper-fraction.js | 35 ++++++++++++++++++- 1 file changed, 34 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 a4739af77..965dded82 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 @@ -8,9 +8,18 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - if (numerator < denominator) { + if (Math.abs(numerator) < Math.abs(denominator)) { return true; } + if ( + Math.abs(numerator) > Math.abs(denominator) || + numerator === denominator + ) { + return false; + } + if(Number.isNaN(numerator) || Number.isNaN(denominator)){ + throw new Error("Not a number") + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -46,6 +55,7 @@ assertEquals(improperFraction, false); // target output: true // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); +assertEquals(negativeFraction, true); // ====> complete with your assertion // Equal Numerator and Denominator check: @@ -53,7 +63,30 @@ const negativeFraction = isProperFraction(-4, 7); // target output: false // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); +assertEquals(equalFraction, false); // ====> complete with your assertion // Stretch: // What other scenarios could you test for? + +//Both Numerator and Denominator are negative check: +// Input: numerator = -4, denominator = -3 +// target output: false +// Explanation:The fraction -4/-3 is not a proper fraction because the absolute value o the numerator is bigger than the absolute value of the denominator +const bothNegativeFraction = isProperFraction(-4, -3); +assertEquals(bothNegativeFraction, false); + +//Numerator is bigger than the negative Denominator's absolute value: +// Input: numerator = 4, denominator = -9 +// target output: true +// Explanation:The fraction 4/-9 is a proper fraction because the absolute value of the denominator is smaller than the the value of the numerator +const negativeDenominator=isProperFraction(4,-9) +assertEquals(negativeDenominator,true) + + + + + +//got stuck on this one, don't know how to test +// const notANumber=isProperFraction("a",2) + // assertEquals(negativeFraction, "Not a number"); \ No newline at end of file From 9f3ed4fc1ef08c95d3cbea56cf888626776ffba5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 31 Jan 2026 08:03:09 +0000 Subject: [PATCH 07/16] assigned rang with the value of card[0] --- .../implement/3-get-card-value.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 266525d1b..76e8efc98 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 @@ -8,9 +8,11 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { - if (rank === "A") { + let rank=card[0] + if (rank=== "A") { return 11; } + } // The line below allows us to load the getCardValue function into tests in other files. @@ -31,14 +33,15 @@ function assertEquals(actualOutput, targetOutput) { // Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), // When the function getCardValue is called with this card string as input, // Then it should return the numerical card value -const aceofSpades = getCardValue("A♠"); -assertEquals(aceofSpades, 11); +const aceOfSpades = getCardValue("A♠"); +assertEquals(aceOfSpades, 11); // Handle Number Cards (2-10): // Given a card with a rank between "2" and "9", // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). -const fiveofHearts = getCardValue("5♥"); +const fiveOfHearts = getCardValue("5♥"); +assertEquals(fiveOfHearts,5) // ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): From 366621c5f27759777212b5ac54683bd3494be1e7 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sat, 31 Jan 2026 14:25:27 +0000 Subject: [PATCH 08/16] Implement logic to handle number and face cards in getCardValue function --- .../implement/3-get-card-value.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 76e8efc98..7d7cea19a 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 @@ -8,11 +8,16 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { - let rank=card[0] + let rank=card.slice(0,-1) if (rank=== "A") { return 11; } - + if(rank>=2 && rank<=9){ + return +rank + } + if(rank==="J") { + return 10 + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -48,6 +53,8 @@ assertEquals(fiveOfHearts,5) // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const faceCards = getCardValue("J♠"); +assertEquals(faceCards,10) // Handle Ace (A): // Given a card with a rank of "A", From 35c308308846cdec451a61a99364e7ca050195f6 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 08:34:40 +0000 Subject: [PATCH 09/16] Refactor isProperFraction function to handle NaN inputs and improve logic for proper fraction checks --- .../implement/2-is-proper-fraction.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 965dded82..318637b40 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 @@ -8,6 +8,7 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { + if (Math.abs(numerator) < Math.abs(denominator)) { return true; } @@ -17,9 +18,10 @@ function isProperFraction(numerator, denominator) { ) { return false; } - if(Number.isNaN(numerator) || Number.isNaN(denominator)){ - throw new Error("Not a number") + if (typeof numerator === "number" && typeof denominator === "number") { + return true; } + } // The line below allows us to load the isProperFraction function into tests in other files. @@ -88,5 +90,5 @@ assertEquals(negativeDenominator,true) //got stuck on this one, don't know how to test -// const notANumber=isProperFraction("a",2) - // assertEquals(negativeFraction, "Not a number"); \ No newline at end of file + const notANumber=isProperFraction("a",2) + assertEquals(notANumber,false); \ No newline at end of file From 83a3f77e493520016b2366681d1c50f08af3037c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 09:46:29 +0000 Subject: [PATCH 10/16] wrote tests to check cards validity and implemented the function to pass the tests --- .../implement/3-get-card-value.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 7d7cea19a..39bc446e7 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 @@ -7,6 +7,7 @@ // complete the rest of the tests and cases // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers +const assert = require("assert"); function getCardValue(card) { let rank=card.slice(0,-1) if (rank=== "A") { @@ -15,9 +16,10 @@ function getCardValue(card) { if(rank>=2 && rank<=9){ return +rank } - if(rank==="J") { + if(/^(10|J|Q|K)$/.test(rank)) { return 10 } + throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -53,15 +55,25 @@ assertEquals(fiveOfHearts,5) // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. -const faceCards = getCardValue("J♠"); +const faceCards = getCardValue("K♠"); assertEquals(faceCards,10) +const faceCards1 = getCardValue("10♠"); +assertEquals(faceCards1, 10); + // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const aceOfSpades1 = getCardValue("A♠"); +assertEquals(aceOfSpades1, 11); // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + + +assert.throws(() => getCardValue("L♠"), Error, /Invalid card/); +assert.throws(() => getCardValue(), Error, /Invalid card/); +assert.throws(() => getCardValue(["A♠"]), Error, /Invalid card/); \ No newline at end of file From 6c0b2c0703aea4c5664b4d9e2ffd63fed4129426 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 11:56:23 +0000 Subject: [PATCH 11/16] Add tests for angle type identification in getAngleType function --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 4a92a3e82..2d111cdf7 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,15 +12,27 @@ test("should identify right angle (90°)", () => { // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" +test("should identify acute angle (angle<90°)", () => { + expect(getAngleType(80)).toEqual("Acute angle"); +}); // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify obtuse angle (90 { + expect(getAngleType(110)).toEqual("Obtuse angle"); +}); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify straight angle (angle=180)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" +test("should identify reflex angle (180 { + expect(getAngleType(210)).toEqual("Reflex angle"); +}); \ No newline at end of file From 79fd50128281f26eff97b53b86ee3eba3c42244e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:16:24 +0000 Subject: [PATCH 12/16] Add validation for card input in getCardValue function --- .../implement/3-get-card-value.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 39bc446e7..b0de137a1 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 @@ -9,6 +9,9 @@ // just make one change at a time -- don't rush -- programmers are deep and careful thinkers const assert = require("assert"); function getCardValue(card) { + if(!/[♠♣♦♥]$/.test(card)){ + throw new Error("Invalid card") + } let rank=card.slice(0,-1) if (rank=== "A") { return 11; @@ -19,7 +22,7 @@ function getCardValue(card) { if(/^(10|J|Q|K)$/.test(rank)) { return 10 } - throw new Error("Invalid card"); + throw new Error("Invalid card rank"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -74,6 +77,7 @@ assertEquals(aceOfSpades1, 11); // Then it should throw an error indicating "Invalid card rank." -assert.throws(() => getCardValue("L♠"), Error, /Invalid card/); -assert.throws(() => getCardValue(), Error, /Invalid card/); -assert.throws(() => getCardValue(["A♠"]), Error, /Invalid card/); \ No newline at end of file +assert.throws(() => getCardValue("L♠"), Error, /Invalid card rank/); +assert.throws(() => getCardValue(), Error, /Invalid card rank/); +assert.throws(() => getCardValue(["A♠"]), Error, /Invalid card rank/); +assert.throws(() => getCardValue("A2"), Error, /Invalid card/); \ No newline at end of file From 7049b83177d54cb988e6f426bc3e992ddb24a960 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:53:38 +0000 Subject: [PATCH 13/16] Fix isProperFraction function to correctly handle equal absolute values of numerator and denominator --- .../implement/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 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 318637b40..b4f29461f 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 @@ -14,7 +14,7 @@ function isProperFraction(numerator, denominator) { } if ( Math.abs(numerator) > Math.abs(denominator) || - numerator === denominator + Math.abs(numerator) === Math.abs(denominator) ) { return false; } From 0492fb431272408c0e9cb0f02649b5d416e6ba78 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:56:36 +0000 Subject: [PATCH 14/16] Add additional test cases for isProperFraction function to cover improper fractions, negative fractions, and equal numerator and denominator scenarios --- .../2-is-proper-fraction.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 caf08d15b..7f801a6f8 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 @@ -7,7 +7,19 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for improper fraction",()=>{ + expect(isProperFraction(3,2)).toEqual(false) +}) // Case 3: Identify Negative Fractions: +test("should return true when the absolute value of the numerator is smaller than the absolute value of the denominator",()=>{ + expect(isProperFraction(-2,9)).toEqual(true); + expect(isProperFraction(2,-9)).toEqual(true) + expect(isProperFraction(-2,-9)).toEqual(true) +}) // Case 4: Identify Equal Numerator and Denominator: +test("should return false for equal numerator and denominator ",()=>{ + expect(isProperFraction(1,1)).toEqual(false) + expect(isProperFraction(-1, 1)).toEqual(false); +}) From 0efeb513d7b578efbb74132fd9c187c580ca7477 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Feb 2026 21:43:27 +0000 Subject: [PATCH 15/16] Refactor getCardValue function to improve error handling and code readability --- .../implement/3-get-card-value.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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 b0de137a1..780867ac1 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 @@ -9,18 +9,18 @@ // just make one change at a time -- don't rush -- programmers are deep and careful thinkers const assert = require("assert"); function getCardValue(card) { - if(!/[♠♣♦♥]$/.test(card)){ - throw new Error("Invalid card") + if (!/[♠♣♦♥]$/.test(card)) { + throw new Error("Invalid, card does not have a face"); } - let rank=card.slice(0,-1) - if (rank=== "A") { + let rank = card.slice(0, -1); + if (rank === "A") { return 11; } - if(rank>=2 && rank<=9){ - return +rank + if (rank >= 2 && rank <= 9) { + return +rank; } - if(/^(10|J|Q|K)$/.test(rank)) { - return 10 + if (/^(10|J|Q|K)$/.test(rank)) { + return 10; } throw new Error("Invalid card rank"); } @@ -51,7 +51,7 @@ assertEquals(aceOfSpades, 11); // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveOfHearts = getCardValue("5♥"); -assertEquals(fiveOfHearts,5) +assertEquals(fiveOfHearts, 5); // ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): @@ -59,11 +59,10 @@ assertEquals(fiveOfHearts,5) // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. const faceCards = getCardValue("K♠"); -assertEquals(faceCards,10) +assertEquals(faceCards, 10); const faceCards1 = getCardValue("10♠"); assertEquals(faceCards1, 10); - // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, @@ -76,8 +75,11 @@ assertEquals(aceOfSpades1, 11); // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." - assert.throws(() => getCardValue("L♠"), Error, /Invalid card rank/); assert.throws(() => getCardValue(), Error, /Invalid card rank/); assert.throws(() => getCardValue(["A♠"]), Error, /Invalid card rank/); -assert.throws(() => getCardValue("A2"), Error, /Invalid card/); \ No newline at end of file +assert.throws( + () => getCardValue("A2"), + Error, + /Invalid, card does not have a face/ +); From cac4339691ae744a8e8b25d9d8e6f3a26ad6d7e1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:34:44 +0000 Subject: [PATCH 16/16] wrote jest tests for the getCardValue function --- .../3-get-card-value.test.js | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 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 04418ff72..9a96dad7f 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 @@ -2,12 +2,46 @@ // We will use the same function, but write tests for it using Jest in this file. const getCardValue = require("../implement/3-get-card-value"); -test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); - expect(aceofSpades).toEqual(11); -}); + // Case 2: Handle Number Cards (2-10): +test("should return the number on the card ", () => { + expect(getCardValue("10♠")).toEqual(10); + expect(getCardValue("8♠")).toEqual(8); + expect(getCardValue("2♠")).toEqual(2); +}); + // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for ( J or Q or K) of spades",()=>{ + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}) // Case 4: Handle Ace (A): +test("should return 11 for Ace of Spades", () => { + const aceOfSpades = getCardValue("A♠"); + expect(aceOfSpades).toEqual(11); +}); + // Case 5: Handle Invalid Cards: +test("should return 'Invalid, card does not have a face' for '5'",()=>{ + expect(()=>{getCardValue("5")}).toThrow("Invalid, card does not have a face"); +}); + +test("should return 'Invalid, card does not have a face' for 'AQ'", () => { + expect(() => { + getCardValue("AQ"); + }).toThrow("Invalid, card does not have a face"); +}); + +test("should return 'Invalid card rank' for 1 of spades",()=>{ + expect(() => { + getCardValue("1♠"); + }).toThrow("Invalid card rank"); +}); + +test("should return 'Invalid card rank' for 15 of spades", () => { + expect(() => { + getCardValue("15♠"); + }).toThrow("Invalid card rank"); +});