From f960b94b8cf7d4e06f65da73b3c933401fcab18c Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Sun, 1 Mar 2026 19:58:48 +0000 Subject: [PATCH 01/11] Sprint 3: Implement functions and rewrite tests in Jest --- .../implement/1-get-angle-type.js | 29 ++++++++- .../implement/2-is-proper-fraction.js | 16 ++++- .../implement/3-get-card-value.js | 65 ++++++++++++++++--- 3 files changed, 96 insertions(+), 14 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 9e05a871e2..207beec6d9 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 @@ -6,7 +6,8 @@ // - "Obtuse angle" for angles greater than 90° and less than 180° // - "Straight angle" for exactly 180° // - "Reflex angle" for angles greater than 180° and less than 360° -// - "Invalid angle" for angles outside the valid range. +// - "(angle >= 0 || angle <= 90){ + // Invalid angle" for angles outside the valid range. // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) @@ -15,7 +16,17 @@ // execute the code to ensure all tests pass. 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. @@ -33,5 +44,19 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles +const acute = getAngleType(45) +assertEquals(acute, "Acute angle"); const right = getAngleType(90); assertEquals(right, "Right angle"); +const obtuse = getAngleType(110) +assertEquals(obtuse, "Obtuse angle"); +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); +const reflex = getAngleType(250); +assertEquals(reflex, "Reflex angle"); +const invalid = getAngleType(380); +assertEquals(invalid, "Invalid angle"); +const invalid2 = getAngleType(0); +assertEquals(invalid2, "Invalid angle"); +const invalid3 = getAngleType(-10); +assertEquals(invalid3, "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..9a0edb4b9b 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,11 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if(numerator <= 0 || denominator <= 0){ + return false; + }else if(numerator < denominator){ + return true; + }else return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -20,8 +25,7 @@ module.exports = isProperFraction; // Here's our helper again function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, + console.assert(actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); } @@ -30,4 +34,10 @@ function assertEquals(actualOutput, targetOutput) { // What combinations of numerators and denominators should you test? // Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 2), "true"); +assertEquals(isProperFraction(3, 2), "false"); +assertEquals(isProperFraction(1, 0), "false"); +assertEquals(isProperFraction(8, 9), "true"); +assertEquals(isProperFraction(0, 1), "false"); +assertEquals(isProperFraction(-4, 1), "false"); +assertEquals(isProperFraction(2, -4), "false"); \ 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..33e4c32c21 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,9 +22,25 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + if (typeof card !== "string") { + throw new Error("Invalid card"); + } + let rank = card.slice(0, -1); // Get everything except the last character + let suit = card.slice(-1); // Get the last character + + const validSuits = ["♠", "♥", "♦", "♣"]; // check if suit is valid + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + if (rank === "A"){ + return 11; + }else if(rank.match(/J|Q|K/)){ + return 10; + }else if(rank.match(/^(10|[2-9])$/)){ + return Number(rank); + }else throw new Error("Invalid card"); +} // 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. module.exports = getCardValue; @@ -36,17 +52,48 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${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("Q♥"), 10); +assertEquals(getCardValue("K♠"), 10); +assertEquals(getCardValue("3♦"), 3); -// Handling invalid cards try { - getCardValue("invalid"); + getCardValue("J"); - // This line will not be reached if an error is thrown as expected + // The below line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); -} catch (e) {} - +} catch (e) { + console.log('Test passed for "J": caught error ->', e.message); +} // What other invalid card cases can you think of? + +try { + getCardValue("9X"); // invalid suit + console.error('Test failed for "9X": error was not thrown'); +} catch (e) { + console.log('Test passed for "9X": caught error ->', e.message); +} + +try { + getCardValue("1♠"); // invalid rank + console.error('Test failed for "1♠": error was not thrown'); +} catch (e) { + console.log('Test passed for "1♠": caught error ->', e.message); +} + +try { + getCardValue("0♥"); // invalid rank + console.error('Test failed for "0♥": error was not thrown'); +} catch (e) { + console.log('Test passed for "0♥": caught error ->', e.message); +} + +try { + getCardValue("ABC"); // completely wrong format + console.error('Test failed for "ABC": error was not thrown'); +} catch (e) { + console.log('Test passed for "ABC": caught error ->', e.message); +} From 773ddc9365926797b8d5e10f730299a366286059 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Tue, 10 Mar 2026 09:59:35 +0000 Subject: [PATCH 02/11] Jest tests have been implemented --- .../1-get-angle-type.test.js | 24 +++++++++++++++++++ .../2-is-proper-fraction.test.js | 15 ++++++++++++ .../3-get-card-value.test.js | 16 ++++++++++++- clear | 5 ++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 clear 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..1fa313ca17 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,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // 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 < angle < 180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(150)).toEqual("Obtuse angle"); + expect(getAngleType(179)).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 < angle < 360)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle <= 0 or angle >= 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-40)).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 7f087b2ba1..1fcf12d7cd 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,18 @@ 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 denominator is less than numerator`, () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); +test("should return false when numerator is zero", ()=>{ + expect(isProperFraction(0, 1)).toEqual(false); +}); +test("should return false when numerator is a negative number", ()=>{ + expect(isProperFraction(-2, 2)).toEqual(false); +}); +test("should return false when denominator is a negative number", ()=>{ + expect(isProperFraction(2, -2)).toEqual(false); +}); +test("should return false where both numerator and denominator are negative numbers", ()=> { + expect(isProperFraction(-3, -4)).toEqual(false); +}) \ No newline at end of file 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..d7e23a7053 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 @@ -11,9 +11,23 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +test("Should return the value of rank variable as a number when we are given 2-10", ()=>{ + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♠")).toEqual(10); +}); // Face Cards (J, Q, K) +test(`Should return 10 when given J or Q or K`, () => { + expect(getCardValue("K♠")).toEqual(10); + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); +}) // Invalid Cards - +test("Should return Invalid card", ()=>{ + expect(() => getCardValue(0)).toThrow("Invalid card"); + expect(() => getCardValue("1X")).toThrow("Invalid card"); + expect(() => getCardValue("0♥")).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 diff --git a/clear b/clear new file mode 100644 index 0000000000..a0dbb9c0d1 --- /dev/null +++ b/clear @@ -0,0 +1,5 @@ + acoursework/sprint-2 + acoursework/sprint-2-clean + coursework/sprint-1 +* coursework/sprint-3-implement-and-rewrite + main From fc8717b87763cb76323c1942c1ecb83b0625ac56 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Tue, 10 Mar 2026 10:08:52 +0000 Subject: [PATCH 03/11] Get-angle-type codes have been formated --- .../implement/1-get-angle-type.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 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 207beec6d9..5492c5a437 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 @@ -7,7 +7,7 @@ // - "Straight angle" for exactly 180° // - "Reflex angle" for angles greater than 180° and less than 360° // - "(angle >= 0 || angle <= 90){ - // Invalid angle" for angles outside the valid range. +// Invalid angle" for angles outside the valid range. // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) @@ -16,17 +16,17 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - if(angle > 0 && angle < 90){ + if (angle > 0 && angle < 90) { return "Acute angle"; - }else if(angle === 90){ + } else if (angle === 90) { return "Right angle"; - }else if(angle > 90 && angle < 180){ - return "Obtuse angle" - }else if(angle === 180){ + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { return "Straight angle"; - }else if(angle > 180 && angle < 360){ + } else if (angle > 180 && angle < 360) { return "Reflex angle"; - }else return "Invalid angle"; + } else return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -44,11 +44,11 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -const acute = getAngleType(45) +const acute = getAngleType(45); assertEquals(acute, "Acute angle"); const right = getAngleType(90); assertEquals(right, "Right angle"); -const obtuse = getAngleType(110) +const obtuse = getAngleType(110); assertEquals(obtuse, "Obtuse angle"); const straight = getAngleType(180); assertEquals(straight, "Straight angle"); @@ -59,4 +59,4 @@ assertEquals(invalid, "Invalid angle"); const invalid2 = getAngleType(0); assertEquals(invalid2, "Invalid angle"); const invalid3 = getAngleType(-10); -assertEquals(invalid3, "Invalid angle"); \ No newline at end of file +assertEquals(invalid3, "Invalid angle"); From 9d4539d400b1527dd805e79f9c91ead7fd73e5a6 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Tue, 10 Mar 2026 10:34:18 +0000 Subject: [PATCH 04/11] Implemented Jest test for tricky invalid cards --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 d7e23a7053..a10b60bbc9 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 @@ -28,6 +28,12 @@ test("Should return Invalid card", ()=>{ expect(() => getCardValue("1X")).toThrow("Invalid card"); expect(() => getCardValue("0♥")).toThrow("Invalid card"); }); +// Invalid card format +test("Should throw error for tricky invalid card formats", () => { + expect(() => getCardValue("0x02♠")).toThrow("Invalid card"); + expect(() => getCardValue("QQ♠")).toThrow("Invalid card"); + expect(() => getCardValue("2.1♠")).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 From 694f1cf10a3c7a6e26b516ccb137a6f57d21946e Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Tue, 10 Mar 2026 10:35:48 +0000 Subject: [PATCH 05/11] jest test implemented for tricky invalid cards --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 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 33e4c32c21..65b1ff8cdf 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 @@ -35,7 +35,7 @@ function getCardValue(card) { if (rank === "A"){ return 11; - }else if(rank.match(/J|Q|K/)){ + }else if(/^[JQK]$/.test(rank)){ return 10; }else if(rank.match(/^(10|[2-9])$/)){ return Number(rank); From 10c634764d7ebe9bdd09332d1d2c4347886154ea Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Tue, 10 Mar 2026 11:03:08 +0000 Subject: [PATCH 06/11] isProperFraction is updated --- .../implement/2-is-proper-fraction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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 9a0edb4b9b..7ac6acd514 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,9 +12,9 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function - if(numerator <= 0 || denominator <= 0){ + if(denominator === 0){ return false; - }else if(numerator < denominator){ + }else if(Math.abs(numerator) < Math.abs(denominator)){ return true; }else return false; } From 9fc0d42ff741f8758449fba5a68dd4c0121ae991 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Thu, 12 Mar 2026 13:12:07 +0000 Subject: [PATCH 07/11] Format file with Prettier and revise test descriptions --- .../implement/3-get-card-value.js | 22 +++++++++--------- .../2-is-proper-fraction.test.js | 23 +++++++++++-------- 2 files changed, 25 insertions(+), 20 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 65b1ff8cdf..324981465d 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,24 +22,24 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if (typeof card !== "string") { + if (typeof card !== "string") { throw new Error("Invalid card"); } let rank = card.slice(0, -1); // Get everything except the last character - let suit = card.slice(-1); // Get the last character - + let suit = card.slice(-1); // Get the last character + const validSuits = ["♠", "♥", "♦", "♣"]; // check if suit is valid if (!validSuits.includes(suit)) { throw new Error("Invalid card"); } - if (rank === "A"){ + if (rank === "A") { return 11; - }else if(/^[JQK]$/.test(rank)){ + } else if (/^[JQK]$/.test(rank)) { return 10; - }else if(rank.match(/^(10|[2-9])$/)){ + } else if (rank.match(/^(10|[2-9])$/)) { return Number(rank); - }else throw new Error("Invalid card"); + } else throw new Error("Invalid card"); } // 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. @@ -71,28 +71,28 @@ try { // What other invalid card cases can you think of? try { - getCardValue("9X"); // invalid suit + getCardValue("9X"); // invalid suit console.error('Test failed for "9X": error was not thrown'); } catch (e) { console.log('Test passed for "9X": caught error ->', e.message); } try { - getCardValue("1♠"); // invalid rank + getCardValue("1♠"); // invalid rank console.error('Test failed for "1♠": error was not thrown'); } catch (e) { console.log('Test passed for "1♠": caught error ->', e.message); } try { - getCardValue("0♥"); // invalid rank + getCardValue("0♥"); // invalid rank console.error('Test failed for "0♥": error was not thrown'); } catch (e) { console.log('Test passed for "0♥": caught error ->', e.message); } try { - getCardValue("ABC"); // completely wrong format + getCardValue("ABC"); // completely wrong format console.error('Test failed for "ABC": error was not thrown'); } catch (e) { console.log('Test passed for "ABC": caught error ->', e.message); 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 1fcf12d7cd..ac744ba28f 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 @@ -5,21 +5,26 @@ 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 -test(`should return false when denominator is zero`, () => { +test("returns false when denominator is zero", () => { expect(isProperFraction(1, 0)).toEqual(false); }); -test(`should return false when denominator is less than numerator`, () => { - expect(isProperFraction(2, 1)).toEqual(false); -}); -test("should return false when numerator is zero", ()=>{ + +test("returns false when numerator is zero", () => { expect(isProperFraction(0, 1)).toEqual(false); }); -test("should return false when numerator is a negative number", ()=>{ + +test("returns false when numerator > denominator", () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); + +test("returns false when numerator is negative", () => { expect(isProperFraction(-2, 2)).toEqual(false); }); -test("should return false when denominator is a negative number", ()=>{ + +test("returns false when denominator is negative", () => { expect(isProperFraction(2, -2)).toEqual(false); }); -test("should return false where both numerator and denominator are negative numbers", ()=> { + +test("returns false when both numerator and denominator are negative", () => { expect(isProperFraction(-3, -4)).toEqual(false); -}) \ No newline at end of file +}); From 842dbaa60ba8c0b81f79008dcee56aae6376609a Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Fri, 13 Mar 2026 09:56:32 +0000 Subject: [PATCH 08/11] Tests passes all cases and updated test description and formated with prettier extension --- .../implement/2-is-proper-fraction.js | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 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 7ac6acd514..c39adba3af 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,33 +11,40 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function - if(denominator === 0){ + if (denominator === 0) { return false; - }else if(Math.abs(numerator) < Math.abs(denominator)){ + } else if (Math.abs(numerator) < Math.abs(denominator)) { return true; - }else return false; + } else return false; } -// 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; - // Here's our helper again function assertEquals(actualOutput, targetOutput) { - console.assert(actualOutput === targetOutput, + console.assert( + actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); } // TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), "true"); -assertEquals(isProperFraction(3, 2), "false"); -assertEquals(isProperFraction(1, 0), "false"); -assertEquals(isProperFraction(8, 9), "true"); -assertEquals(isProperFraction(0, 1), "false"); -assertEquals(isProperFraction(-4, 1), "false"); -assertEquals(isProperFraction(2, -4), "false"); \ No newline at end of file + +// numerator < denominator (in absolute value) → proper fraction +assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(8, 9), true); +assertEquals(isProperFraction(0, 5), true); // numerator = 0 + +// numerator > denominator (in absolute value) → improper fraction +assertEquals(isProperFraction(3, 2), false); +assertEquals(isProperFraction(-4, 1), false); + +// numerator = denominator (in absolute value) → not a proper fraction +assertEquals(isProperFraction(5, 5), false); +assertEquals(isProperFraction(-7, -7), false); + +// denominator = 0 → invalid fraction +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 0), false); + +// negative numbers still follow the rule: numerator < denominator (in absolute value) +assertEquals(isProperFraction(2, -4), true); +assertEquals(isProperFraction(-2, -5), true); From 853bea5d8cb0ec0ac080d830e80b8451b4673374 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Fri, 13 Mar 2026 16:11:22 +0000 Subject: [PATCH 09/11] jest test description now matches with the function --- .../2-is-proper-fraction.test.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 ac744ba28f..6d6ae6b651 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,27 +4,30 @@ 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 -test("returns false when denominator is zero", () => { - expect(isProperFraction(1, 0)).toEqual(false); +test("returns true when |numerator| < |denominator|", () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +test("returns true when numerator is zero", () => { + expect(isProperFraction(0, 5)).toEqual(true); }); -test("returns false when numerator is zero", () => { - expect(isProperFraction(0, 1)).toEqual(false); +test("returns false when |numerator| > |denominator|", () => { + expect(isProperFraction(3, 2)).toEqual(false); }); -test("returns false when numerator > denominator", () => { - expect(isProperFraction(2, 1)).toEqual(false); +test("returns false when |numerator| = |denominator|", () => { + expect(isProperFraction(5, 5)).toEqual(false); }); -test("returns false when numerator is negative", () => { - expect(isProperFraction(-2, 2)).toEqual(false); +test("returns false when denominator is zero", () => { + expect(isProperFraction(1, 0)).toEqual(false); }); -test("returns false when denominator is negative", () => { - expect(isProperFraction(2, -2)).toEqual(false); +test("returns true when denominator is negative but |numerator| < |denominator|", () => { + expect(isProperFraction(2, -4)).toEqual(true); }); -test("returns false when both numerator and denominator are negative", () => { - expect(isProperFraction(-3, -4)).toEqual(false); +test("returns true when both numbers are negative but |numerator| < |denominator|", () => { + expect(isProperFraction(-3, -4)).toEqual(true); }); From f87ef8056350b8506771a60df78771c80886f633 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Fri, 13 Mar 2026 16:13:12 +0000 Subject: [PATCH 10/11] is properFunction updated --- .../implement/2-is-proper-fraction.js | 1 + 1 file changed, 1 insertion(+) 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 c39adba3af..6dc8e753c9 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 @@ -17,6 +17,7 @@ function isProperFraction(numerator, denominator) { return true; } else return false; } +module.exports = isProperFraction; // Here's our helper again function assertEquals(actualOutput, targetOutput) { From 14ffae5fa5a7bc93f65ec9802b4fd85f8f1ed90d Mon Sep 17 00:00:00 2001 From: Ahmad Roman Sanaye Date: Fri, 13 Mar 2026 19:07:30 +0000 Subject: [PATCH 11/11] clear has been deleted --- clear | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 clear diff --git a/clear b/clear deleted file mode 100644 index a0dbb9c0d1..0000000000 --- a/clear +++ /dev/null @@ -1,5 +0,0 @@ - acoursework/sprint-2 - acoursework/sprint-2-clean - coursework/sprint-1 -* coursework/sprint-3-implement-and-rewrite - main