From 13d8ab749e79b56b64e0f6070780045e80dd9523 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 17 Feb 2026 17:29:59 +0000 Subject: [PATCH 1/9] added test cases for different types of angles and amended getAngleType function to pass them --- .../implement/1-get-angle-type.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 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 ca1dfe7f2..2ce43ab79 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,8 +11,16 @@ function getAngleType(angle) { if (angle === 90) { return "Right 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 < 90) { + return "Acute angle"; + } + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } + return "Reflex angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -50,14 +58,16 @@ 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); -// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(obtuse, "Obtuse angle"); // 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"); // 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 +const reflex = getAngleType(340); +assertEquals(reflex, "Reflex angle"); From 649826a3604871d2d7ea7045b104afb8fecfd10e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:12:40 +0000 Subject: [PATCH 2/9] added tests to check for proper fraction --- .../implement/2-is-proper-fraction.js | 38 +++++++++++++++++-- 1 file changed, 34 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 a4739af77..1684c2161 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,10 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - if (numerator < denominator) { - return true; - } + if (typeof numerator !== "number" || typeof denominator !== "number") + return "Use only numbers"; + + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. @@ -46,14 +47,43 @@ 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); -// ====> complete with your assertion +assertEquals(negativeFraction, true); // Equal Numerator and Denominator check: // Input: numerator = 3, denominator = 3 // 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? + +// Negative Fraction check: +// Input: numerator = 4, denominator = -7 +// target output: true +// Explanation: The fraction 4/-7 is a proper fraction because the numerator (4) is less than the absolute value of the denominator (7). The function should return true. +const negativeFraction2 = isProperFraction(4, -7); +assertEquals(negativeFraction2, true); + +// Negative Fraction check: +// Input: numerator = -4, denominator = -7 +// target output: true +// Explanation: The fraction -4/-7 is a proper fraction because the absolute value of the numerator (4) is less than the absolute value of the denominator (7). The function should return true. +const negativeFraction3 = isProperFraction(-4, -7); +assertEquals(negativeFraction3, true); + +//Invalid input +//Input:numerator = "q", denominator = 7 +// target output: message +//Explanation: the fraction only takes numbers +const notANumber = isProperFraction("q", 7); +assertEquals(notANumber, "Use only numbers"); + +//Invalid input +//Input:numerator = 7, denominator = "q" +// target output: message +//Explanation: the fraction only takes numbers +const notANumber2 = isProperFraction(7, "q"); +assertEquals(notANumber2, "Use only numbers"); From 595eed1d526d0dd3f15657a0678933b0e7891b68 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:16:51 +0000 Subject: [PATCH 3/9] added assert for incomplete fraction --- .../implement/2-is-proper-fraction.js | 4 ++++ 1 file changed, 4 insertions(+) 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 1684c2161..9ca529b63 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 (!numerator || !denominator) return "Incomplete fraction"; if (typeof numerator !== "number" || typeof denominator !== "number") return "Use only numbers"; @@ -87,3 +88,6 @@ assertEquals(notANumber, "Use only numbers"); //Explanation: the fraction only takes numbers const notANumber2 = isProperFraction(7, "q"); assertEquals(notANumber2, "Use only numbers"); + +const incompleteFraction = isProperFraction(2); +assertEquals(incompleteFraction, "Incomplete fraction"); From 996ebedf1ed6c34e54b06974a549774511dcdeb5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 09:02:13 +0000 Subject: [PATCH 4/9] added test case for incomplete fraction input handling --- .../implement/2-is-proper-fraction.js | 5 +++++ 1 file changed, 5 insertions(+) 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 9ca529b63..19f4ab9bd 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 @@ -89,5 +89,10 @@ assertEquals(notANumber, "Use only numbers"); const notANumber2 = isProperFraction(7, "q"); assertEquals(notANumber2, "Use only numbers"); + +//Incomplete input +//Input:2 +// target output: message +//Explanation: the fraction needs both a numerator and a denominator const incompleteFraction = isProperFraction(2); assertEquals(incompleteFraction, "Incomplete fraction"); From 2e73bdc2898918db13ee74a02cfe034656a4f7b0 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 09:32:54 +0000 Subject: [PATCH 5/9] implemented card value logic and added tests for face cards and error handling --- .../implement/3-get-card-value.js | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 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..c73e508b7 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,24 @@ // 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.slice(0, -1); + let cardFace = card[card.length - 1]; + + if (!["♠", "♥", "♦", "♣"].includes(cardFace)) { + throw new Error(`Invalid card face: ${cardFace}`); + } if (rank === "A") { return 11; } + if (+rank >= 2 && +rank <= 9) { + return +rank; + } + if (["K", "10", "Q", "J"].includes(rank)) { + return 10; + } + if (!["♠", "♥", "♦", "♣"].includes(cardFace)) { + } + throw new Error(`Invalid card rank: ${rank}`); } // The line below allows us to load the getCardValue function into tests in other files. @@ -26,26 +41,28 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } + // Acceptance criteria: // 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♥"); -// ====> write your test here, and then add a line to pass the test in the function above +const fiveOfHearts = getCardValue("5♥"); +assertEquals(fiveOfHearts, 5); // Handle Face Cards (J, Q, K): // 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 kingOfHearts = getCardValue("K♥"); +assertEquals(kingOfHearts, 10); // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, @@ -55,3 +72,16 @@ const fiveofHearts = getCardValue("5♥"); // 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." +try { + getCardValue("2"); + throw new Error("Should have thrown an error for invalid card"); +} catch (error) { + assertEquals(error.message, "Invalid card face: 2"); +} + +try { + getCardValue("1♥"); + throw new Error("Should have thrown an error for invalid card"); +} catch (error) { + assertEquals(error.message, "Invalid card rank: 1"); +} From cdd8a97de1260b236c36abf1cc60e89a483f46a5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 09:52:35 +0000 Subject: [PATCH 6/9] added tests to identify acute, obtuse, straight, and reflex angles in getAngleType function --- .../1-get-angle-type.test.js | 14 ++++++++++++++ 1 file changed, 14 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..550441a8b 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,29 @@ 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 (80°)",()=>{ + 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(110°)",()=>{ + 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(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(280°)",()=>{ + expect(getAngleType(280)).toEqual("Reflex angle") +}); \ No newline at end of file From 26a311926fbb667d8aeec3403e7c5684e37e94c1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 10:00:28 +0000 Subject: [PATCH 7/9] added tests for improper fractions, negative proper fractions, and equal numerator and denominator cases in isProperFraction function --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 9 +++++++++ 1 file changed, 9 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..96927731b 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,16 @@ 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 for negative proper fraction",()=>{ + expect(isProperFraction(-2,7)).toEqual(true) +}) // Case 4: Identify Equal Numerator and Denominator: +test("should return false for equal nominator and denominator",()=>{ + expect(isProperFraction(2,2)).toEqual(false) +}) From 7a00c6a07e25744d7fd423d7e5902f4da8f67bb3 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 10:01:37 +0000 Subject: [PATCH 8/9] fix: correct variable name for Ace of Spades test in getCardValue tests --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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..fbc28b5fc 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,8 +3,8 @@ const getCardValue = require("../implement/3-get-card-value"); test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); - expect(aceofSpades).toEqual(11); + const aceOfSpades = getCardValue("A♠"); + expect(aceOfSpades).toEqual(11); }); // Case 2: Handle Number Cards (2-10): From f89c2e1d80e85a7ffd8c83e2864a17023caff5b0 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 10:20:15 +0000 Subject: [PATCH 9/9] refactor: reorganize tests for getCardValue function for clarity and consistency --- .../3-get-card-value.test.js | 25 ++++++++++++++++--- 1 file changed, 21 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 fbc28b5fc..51ee05175 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,29 @@ // 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 5 for five of spades ",()=>{ + const fiveOfSpades = getCardValue("5♠"); + expect(fiveOfSpades).toEqual(5) +}) // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for king of spades",()=>{ + const kingOfSpades = getCardValue("K♠"); + expect(kingOfSpades).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 through error for 1 of spades",()=>{ + expect(()=> getCardValue("1♠")).toThrow('Invalid card rank: 1') +}) + + +test("should throw error for five*",()=>{ + expect(() => getCardValue("5*")).toThrow("Invalid card face: *"); +}) \ No newline at end of file