From 40e06726359b70d2795544093a0eccabba7a24a1 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Mon, 29 Jun 2026 15:16:58 +0100 Subject: [PATCH 01/12] Sprint-3 implementation added --- .../implement/1-get-angle-type.js | 78 +++++++++++++++-- .../implement/2-is-proper-fraction.js | 47 ++++++++-- .../implement/3-get-card-value.js | 87 ++++++++++++++++--- 3 files changed, 182 insertions(+), 30 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..758334ea47 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 @@ -15,23 +15,83 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + else if (angle == 90) { + return "Right angle"; + } + else if (angle == 180) { + return "Straight angle"; + } + else if (angle > 0 && angle < 90) { + return "Acute angle"; + } + else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + else + return "Reflex 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; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); } +const invalid = getAngleType(0); +assertEquals(invalid, "Invalid angle"); +console.log (getAngleType(0)); + +const invalid0 = getAngleType(-10); +assertEquals(invalid, "Invalid angle"); +console.log (getAngleType(-10)); + +const invalid1 = getAngleType(360); +assertEquals(invalid1, "Invalid angle"); +console.log (getAngleType(360)); + +const invalid2 = getAngleType(900); +assertEquals(invalid2, "Invalid angle"); +console.log (getAngleType(900)); -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); +console.log (getAngleType(90)); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); +console.log (getAngleType(180)); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); +console.log (getAngleType(45)); + +const obtuse = getAngleType(135); +assertEquals(obtuse, "Obtuse angle"); +console.log (getAngleType(135)); + +const reflex = getAngleType(240); +assertEquals(reflex, "Reflex angle"); +console.log (getAngleType(240)); + +module.exports = getAngleType; + +// 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; + +// This helper function is written to make our assertions easier to read. +// If the actual output matches the target output, the test will pass +// function assertEquals(actualOutput, targetOutput) { + //console.assert( + //actualOutput === targetOutput, + //`Expected ${actualOutput} to equal ${targetOutput}` + //); +//} + +// TODO: Write tests to cover all cases, including boundary and invalid cases. +// Example: Identify Right Angles +//const right = getAngleType(90); +//assertEquals(right, "Right 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..f4d60d4033 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,14 +11,12 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (numerator < denominator) { + return true; + } + 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, @@ -26,8 +24,43 @@ function assertEquals(actualOutput, targetOutput) { ); } +const case1 = isProperFraction(1, 2); +assertEquals(case1, true); +console.log(isProperFraction(1, 2)); + +const case2 = isProperFraction(3, 4); +assertEquals(case2, true); +console.log(isProperFraction(3, 4)); + +const case3 = isProperFraction(4, 4); +assertEquals(case3, false); +console.log(isProperFraction(4, 4)); + +const case4 = isProperFraction(8, 5); +assertEquals(case4, false); +console.log(isProperFraction(8, 5)); + +const case5 = isProperFraction(16, 22); +assertEquals(case5, true); +console.log(isProperFraction(16, 22)); + +const case6 = isProperFraction(0, 6); +assertEquals(case6, true); +console.log(isProperFraction(0, 6)); + +const case7 = isProperFraction(5, 0); +assertEquals(case7, false); +console.log(isProperFraction(5, 0)); + +module.exports = isProperFraction; + +// 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. + + +// Here's our helper again // 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(1, 2), true); \ 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 ff5c532e1d..4999d61573 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,14 +22,28 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + const rank = card.slice(0, -1); + const suit = card.slice(-1); + + const validRank = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]; + const validSuit = ["♠","♥","♦","♣"]; + + if (!validRank.includes(rank) || !validSuit.includes(suit)) { + throw new Error("Invalid Card"); + } + + if (rank === "A") { + return 11; + } + else if (rank === "J" || rank=== "Q" || rank === "K") { + return 10; + } -// 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; + else if (rank >= 2 && rank <= 10) { + return Number(rank); + } +} -// Helper functions to make our assertions easier to read. function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, @@ -37,18 +51,63 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); +const ace = getCardValue("A♠"); +assertEquals(getCardValue("A♠"), 11); +console.log (getCardValue("A♠")); + +const faceJ = getCardValue("J♣"); +assertEquals(getCardValue("J♣"), 10); +console.log (getCardValue("J♣")); + +const faceQ = getCardValue("Q♦"); +assertEquals(getCardValue("Q♦"), 10); +console.log (getCardValue("Q♦")); + +const faceK = getCardValue("K♦"); +assertEquals(getCardValue("K♦"), 10); +console.log (getCardValue("K♦")); + +const number5 = getCardValue("5♥"); +assertEquals(getCardValue("5♥"), 5); +console.log (getCardValue("5♥")); + +const number10 = getCardValue("10♥"); +assertEquals(getCardValue("10♥"), 10); +console.log (getCardValue("10♥")); -// Handling invalid cards try { - getCardValue("invalid"); + getCardValue("10"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} - // This line will not be reached if an error is thrown as expected +try { + getCardValue("A"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("10x"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("JK"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("Qxx"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } -// What other invalid card cases can you think of? +module.exports = getCardValue; \ No newline at end of file From 3b832f3769ed0918b443b760f7ac18b71849a8cb Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Tue, 30 Jun 2026 13:04:26 +0100 Subject: [PATCH 02/12] rewrite get-angle-type-with-jest --- .../1-get-angle-type.test.js | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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..36ff743ebc 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 @@ -1,20 +1,28 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const getAngleType = require("../implement/1-get-angle-type"); -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. - -// Case 1: Acute angles 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"); }); +test(`should return "Right angle" when (0 == 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); +test(`should return "Straight angle" when (0 == 180)`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); +test(`should return "Invalid angle" when (angle <= 0 || angle >= 360)`, () => { + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(370)).toEqual("Invalid angle"); +}); -// Case 2: Right angle -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles From d0c84ec5170ddc4f6471436f62af29c1bb2db2e2 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Tue, 30 Jun 2026 13:58:00 +0100 Subject: [PATCH 03/12] fix conditions for proper fraction --- .../implement/2-is-proper-fraction.js | 10 +++++----- .../2-is-proper-fraction.test.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 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 f4d60d4033..dd220effc1 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,12 +11,12 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if (numerator < denominator) { - return true; + if (numerator <= 0 || denominator <= 0) { + return false; } - return false; + return numerator < denominator; } - + function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, @@ -45,7 +45,7 @@ assertEquals(case5, true); console.log(isProperFraction(16, 22)); const case6 = isProperFraction(0, 6); -assertEquals(case6, true); +assertEquals(case6, false); console.log(isProperFraction(0, 6)); const case7 = isProperFraction(5, 0); 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..c1485c5cf8 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,21 @@ 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 true when the function is proper fraction`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); +test(`should return false when the function is improper fraction`, () => { + expect(isProperFraction(8, 5)).toEqual(false); +}); +test(`should return false when the numerator is equal to denominator`, () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); +test(`should return false when numerator is zero`, () => { + expect(isProperFraction(0, 1)).toEqual(false); +}); +test(`should return false when numerator is negative`, () => { + expect(isProperFraction(-1, 1)).toEqual(false); +}); +test(`should return false when denominator is negative`, () => { + expect(isProperFraction(1, -1)).toEqual(false); +}); \ No newline at end of file From d469d9423d139903226425f220ff71c112819260 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Tue, 30 Jun 2026 17:13:15 +0100 Subject: [PATCH 04/12] rewrite get-card-value with jest --- .../3-get-card-value.test.js | 62 ++++++++++++++----- 1 file changed, 46 insertions(+), 16 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..e4609ff5c5 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 @@ -1,20 +1,50 @@ -// This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const getCardValue = require("../implement/3-get-card-value"); - -// TODO: Write tests in Jest syntax to cover all possible outcomes. - -// 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 - -// 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 - +describe ("Number Cards" , () => { + test(`Should return 5 for 5♥`, () => { + expect(getCardValue("5♥")).toEqual(5); + }); + test(`Should return 10 for 10♥`, () => { + expect(getCardValue("10♥")).toEqual(10); + }); +}); +describe ("Face Cards" , () => { + test(`Should return 10 for J♣`, () => { + expect(getCardValue("J♣")).toEqual(10); + }); + test(`Should return 10 for Q♦`, () => { + expect(getCardValue("Q♦")).toEqual(10); + }); + test(`Should return 10 for K♦`, () => { + expect(getCardValue("K♦")).toEqual(10); + }); +}); + describe("Invalid Cards", () => { + test("throws error for invalid card", () => { + expect(() => { + getCardValue("10"); + }).toThrow(); + }); + test("throws error for invalid card", () => { + expect(() => { + getCardValue("A"); + }).toThrow(); + }); + test("throws error for invalid card", () => { + expect(() => { + getCardValue("10x"); + }).toThrow(); + }); + test("throws error for invalid card", () => { + expect(() => { + getCardValue("JK"); + }).toThrow(); + }); + test("throws error for invalid card", () => { + expect(() => { + getCardValue("Qxx"); + }).toThrow(); + }); +}); From 8fe3c92ba5ca54bb0f46efe9b477b5d82f27bd03 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sun, 12 Jul 2026 22:21:13 +0100 Subject: [PATCH 05/12] made correction in tests --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 36ff743ebc..b87567d6ce 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 @@ -5,7 +5,7 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); -test(`should return "Right angle" when (0 == 90)`, () => { +test(`should return "Right angle" when (angle == 90)`, () => { expect(getAngleType(90)).toEqual("Right angle"); }); test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { @@ -13,7 +13,7 @@ test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { expect(getAngleType(120)).toEqual("Obtuse angle"); expect(getAngleType(179)).toEqual("Obtuse angle"); }); -test(`should return "Straight angle" when (0 == 180)`, () => { +test(`should return "Straight angle" when (angle == 180)`, () => { expect(getAngleType(180)).toEqual("Straight angle"); }); test(`should return "Reflex angle" when (180 < angle < 360)`, () => { From 683731722448620435b3e89e3a75833e735babd5 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sun, 12 Jul 2026 22:53:46 +0100 Subject: [PATCH 06/12] correct indentation --- .../implement/3-get-card-value.js | 57 ++++++++------ .../3-get-card-value.test.js | 76 +++++++++---------- 2 files changed, 72 insertions(+), 61 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 4999d61573..70928974af 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 @@ -25,23 +25,34 @@ function getCardValue(card) { const rank = card.slice(0, -1); const suit = card.slice(-1); - const validRank = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]; - const validSuit = ["♠","♥","♦","♣"]; - - if (!validRank.includes(rank) || !validSuit.includes(suit)) { - throw new Error("Invalid Card"); + const validRank = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + const validSuit = ["♠", "♥", "♦", "♣"]; + + if (!validRank.includes(rank) || !validSuit.includes(suit)) { + throw new Error("Invalid Card"); } if (rank === "A") { return 11; - } - else if (rank === "J" || rank=== "Q" || rank === "K") { + } else if (rank === "J" || rank === "Q" || rank === "K") { return 10; + } else if (rank >= 2 && rank <= 10) { + return Number(rank); } - - else if (rank >= 2 && rank <= 10) { - return Number(rank); - } } function assertEquals(actualOutput, targetOutput) { @@ -53,61 +64,61 @@ function assertEquals(actualOutput, targetOutput) { const ace = getCardValue("A♠"); assertEquals(getCardValue("A♠"), 11); -console.log (getCardValue("A♠")); +console.log(getCardValue("A♠")); const faceJ = getCardValue("J♣"); assertEquals(getCardValue("J♣"), 10); -console.log (getCardValue("J♣")); +console.log(getCardValue("J♣")); const faceQ = getCardValue("Q♦"); assertEquals(getCardValue("Q♦"), 10); -console.log (getCardValue("Q♦")); +console.log(getCardValue("Q♦")); const faceK = getCardValue("K♦"); assertEquals(getCardValue("K♦"), 10); -console.log (getCardValue("K♦")); +console.log(getCardValue("K♦")); const number5 = getCardValue("5♥"); assertEquals(getCardValue("5♥"), 5); -console.log (getCardValue("5♥")); +console.log(getCardValue("5♥")); const number10 = getCardValue("10♥"); assertEquals(getCardValue("10♥"), 10); -console.log (getCardValue("10♥")); +console.log(getCardValue("10♥")); try { getCardValue("10"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } try { getCardValue("A"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } try { getCardValue("10x"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } try { getCardValue("JK"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } try { getCardValue("Qxx"); console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log("Error thrown for invalid card 🎉"); } -module.exports = getCardValue; \ No newline at end of file +module.exports = getCardValue; 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 e4609ff5c5..ca2f23fe69 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,49 +2,49 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -describe ("Number Cards" , () => { - test(`Should return 5 for 5♥`, () => { - expect(getCardValue("5♥")).toEqual(5); - }); - test(`Should return 10 for 10♥`, () => { - expect(getCardValue("10♥")).toEqual(10); - }); +describe("Number Cards", () => { + test(`Should return 5 for 5♥`, () => { + expect(getCardValue("5♥")).toEqual(5); + }); + test(`Should return 10 for 10♥`, () => { + expect(getCardValue("10♥")).toEqual(10); + }); }); -describe ("Face Cards" , () => { - test(`Should return 10 for J♣`, () => { - expect(getCardValue("J♣")).toEqual(10); - }); - test(`Should return 10 for Q♦`, () => { - expect(getCardValue("Q♦")).toEqual(10); - }); - test(`Should return 10 for K♦`, () => { - expect(getCardValue("K♦")).toEqual(10); - }); +describe("Face Cards", () => { + test(`Should return 10 for J♣`, () => { + expect(getCardValue("J♣")).toEqual(10); + }); + test(`Should return 10 for Q♦`, () => { + expect(getCardValue("Q♦")).toEqual(10); + }); + test(`Should return 10 for K♦`, () => { + expect(getCardValue("K♦")).toEqual(10); + }); }); - describe("Invalid Cards", () => { +describe("Invalid Cards", () => { test("throws error for invalid card", () => { - expect(() => { - getCardValue("10"); - }).toThrow(); - }); + expect(() => { + getCardValue("10"); + }).toThrow(); + }); test("throws error for invalid card", () => { - expect(() => { - getCardValue("A"); - }).toThrow(); - }); + expect(() => { + getCardValue("A"); + }).toThrow(); + }); test("throws error for invalid card", () => { - expect(() => { - getCardValue("10x"); - }).toThrow(); - }); + expect(() => { + getCardValue("10x"); + }).toThrow(); + }); test("throws error for invalid card", () => { - expect(() => { - getCardValue("JK"); - }).toThrow(); - }); + expect(() => { + getCardValue("JK"); + }).toThrow(); + }); test("throws error for invalid card", () => { - expect(() => { - getCardValue("Qxx"); - }).toThrow(); - }); + expect(() => { + getCardValue("Qxx"); + }).toThrow(); + }); }); From b68e8bb78f139489c405d5bc8e9f882b74d9e13c Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Tue, 14 Jul 2026 22:03:32 +0100 Subject: [PATCH 07/12] erased commented code for getAngleType --- .../implement/1-get-angle-type.js | 32 ------------------- 1 file changed, 32 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 758334ea47..2b17554726 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 @@ -1,18 +1,3 @@ -// Implement a function getAngleType -// -// When given an angle in degrees, it should return a string indicating the type of angle: -// - "Acute angle" for angles greater than 0° and less than 90° -// - "Right angle" for exactly 90° -// - "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. - -// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. function getAngleType(angle) { if (angle <= 0 || angle >= 360) { @@ -78,20 +63,3 @@ console.log (getAngleType(240)); module.exports = getAngleType; -// 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; - -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -// function assertEquals(actualOutput, targetOutput) { - //console.assert( - //actualOutput === targetOutput, - //`Expected ${actualOutput} to equal ${targetOutput}` - //); -//} - -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -//const right = getAngleType(90); -//assertEquals(right, "Right angle"); \ No newline at end of file From f38f79fa078c0afba1e9cef9823f3c1a16c0db70 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Tue, 14 Jul 2026 23:39:06 +0100 Subject: [PATCH 08/12] add correct logic for proper fraction --- .../implement/2-is-proper-fraction.js | 9 ++++++--- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 4 ++-- 2 files changed, 8 insertions(+), 5 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 dd220effc1..b9b91dd655 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,10 +11,13 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if (numerator <= 0 || denominator <= 0) { + if (denominator === 0) { return false; } - return numerator < denominator; + else if (numerator >= 0 && denominator !== 0) { + + return Math.abs(numerator) < Math.abs(denominator); + } } function assertEquals(actualOutput, targetOutput) { @@ -45,7 +48,7 @@ assertEquals(case5, true); console.log(isProperFraction(16, 22)); const case6 = isProperFraction(0, 6); -assertEquals(case6, false); +assertEquals(case6, true); console.log(isProperFraction(0, 6)); const case7 = isProperFraction(5, 0); 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 c1485c5cf8..f449e2e691 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 @@ -17,8 +17,8 @@ test(`should return false when the function is improper fraction`, () => { test(`should return false when the numerator is equal to denominator`, () => { expect(isProperFraction(4, 4)).toEqual(false); }); -test(`should return false when numerator is zero`, () => { - expect(isProperFraction(0, 1)).toEqual(false); +test(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, 1)).toEqual(true); }); test(`should return false when numerator is negative`, () => { expect(isProperFraction(-1, 1)).toEqual(false); From c4869730a9197bcff534631542d5580c8eeaa776 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Wed, 15 Jul 2026 00:15:29 +0100 Subject: [PATCH 09/12] remove unnecessary condition for valid card --- .../implement/3-get-card-value.js | 4 +--- .../3-get-card-value.test.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 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 70928974af..48d6cb5879 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 @@ -50,9 +50,7 @@ function getCardValue(card) { return 11; } else if (rank === "J" || rank === "Q" || rank === "K") { return 10; - } else if (rank >= 2 && rank <= 10) { - return Number(rank); - } + } else return Number(rank); } function assertEquals(actualOutput, targetOutput) { 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 ca2f23fe69..b0e2cad4dd 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 @@ -47,4 +47,24 @@ describe("Invalid Cards", () => { getCardValue("Qxx"); }).toThrow(); }); + test("throws error for invalid suit", () => { + expect(() => { + getCardValue("*"); + }).toThrow(); + }); + test("throws error for invalid suit", () => { + expect(() => { + getCardValue("diamonds"); + }).toThrow(); + }); + test("throws error for invalid suit", () => { + expect(() => { + getCardValue("♤"); + }).toThrow(); + }); + test("throws error for invalid suit", () => { + expect(() => { + getCardValue("x"); + }).toThrow(); + }); }); From 1e399a1c9ec22790cbc2bc4114227bc47a23753a Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Wed, 15 Jul 2026 00:19:44 +0100 Subject: [PATCH 10/12] add test cases for invalid suits --- .../implement/3-get-card-value.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 48d6cb5879..e2cbe07026 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 @@ -118,5 +118,30 @@ try { } catch (e) { console.log("Error thrown for invalid card 🎉"); } +try { + getCardValue("*"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("diamonds"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("♤"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("x"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + module.exports = getCardValue; From 2007dc309c9dc46b65149c28e8f2680fac8cd0f9 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Thu, 16 Jul 2026 21:03:54 +0100 Subject: [PATCH 11/12] made correct adjustment for properfrac --- .../implement/2-is-proper-fraction.js | 11 +++++++++-- 1 file changed, 9 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 b9b91dd655..d5ea76f509 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,11 +14,10 @@ function isProperFraction(numerator, denominator) { if (denominator === 0) { return false; } - else if (numerator >= 0 && denominator !== 0) { return Math.abs(numerator) < Math.abs(denominator); } -} + function assertEquals(actualOutput, targetOutput) { console.assert( @@ -55,6 +54,14 @@ const case7 = isProperFraction(5, 0); assertEquals(case7, false); console.log(isProperFraction(5, 0)); +const case8 = isProperFraction(-1, 2); +assertEquals(case8, true); +console.log(isProperFraction(-1, 2)); + +const case9 = isProperFraction(1, -2); +assertEquals(case9, true); +console.log(isProperFraction(1, -2)); + module.exports = isProperFraction; // The line below allows us to load the isProperFraction function into tests in other files. From a90ef9f7fe67d0e6e95884bcacaea9d2413383d2 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Thu, 16 Jul 2026 21:08:08 +0100 Subject: [PATCH 12/12] Update proper fraction Jest tests --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 6 ++++++ 1 file changed, 6 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 f449e2e691..3d457eb441 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 @@ -25,4 +25,10 @@ test(`should return false when numerator is negative`, () => { }); test(`should return false when denominator is negative`, () => { expect(isProperFraction(1, -1)).toEqual(false); +}); +test(`should return true when numerator is negative but not the same number as denominator`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); +}); +test(`should return true when denominator is negative but not the same number as denominator`, () => { + expect(isProperFraction(1, -2)).toEqual(true); }); \ No newline at end of file