From 5209d8d740b438f607e647ee35ba721e47f336a1 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Mon, 2 Mar 2026 01:23:50 +0000 Subject: [PATCH 1/7] Angle function and test casese --- .../implement/1-get-angle-type.js | 30 ++++++++++++++++++- 1 file changed, 29 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 9e05a871e2..129a02e30f 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,7 +15,19 @@ // 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 > 0 && angle < 90) { + return "Acute angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -34,4 +46,20 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); +const acute1 = getAngleType(20); +const invalid = getAngleType(0); +const acute3 = getAngleType(89.999); +const obtuse = getAngleType(98.25); +const straightAngle = getAngleType(180); +const invalid1 = getAngleType(360); +const invalidAngle = getAngleType(362); +const reflexAngle2 = getAngleType(210); + assertEquals(right, "Right angle"); +assertEquals(acute1, "Acute angle"); +assertEquals(invalid, "Invalid angle"); +assertEquals(obtuse, "Obtuse angle"); +assertEquals(straightAngle, "Straight angle"); +assertEquals(invalid1, "Invalid angle"); +assertEquals(invalidAngle, "Invalid angle"); +assertEquals(reflexAngle2, "Reflex angle"); From 49570d36d013db6af0a309b3e194e2b1e0318b4c Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Mon, 2 Mar 2026 08:46:11 +0000 Subject: [PATCH 2/7] proper fraction with test cases --- .../implement/1-get-angle-type.js | 2 ++ .../implement/2-is-proper-fraction.js | 14 ++++++++++++++ 2 files changed, 16 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 129a02e30f..4ca24a776b 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 @@ -63,3 +63,5 @@ assertEquals(straightAngle, "Straight angle"); assertEquals(invalid1, "Invalid angle"); assertEquals(invalidAngle, "Invalid angle"); assertEquals(reflexAngle2, "Reflex angle"); +assertEquals(acute3, "Acute angle"); + 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..9045271650 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>denominator) { + return false + }else{ + return true + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +36,12 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 10000), true); +assertEquals(isProperFraction(100, 2), false); +assertEquals(isProperFraction(1, 0.005), false); +assertEquals(isProperFraction(1e2, 1e3), true); +assertEquals(isProperFraction(1e4, 1e0), false); +assertEquals(isProperFraction(-1, 1), true); +assertEquals(isProperFraction(1, -1), false); +assertEquals(isProperFraction(0, -1), false); +assertEquals(isProperFraction(-1, 0), true); From 0ee00b998d6af66aaf36afa9fa9bc0405b47905c Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Mon, 2 Mar 2026 23:11:53 +0000 Subject: [PATCH 3/7] resolved getCard Values with test cases --- .../implement/3-get-card-value.js | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index c7559e787e..9fdcecbb5e 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,7 +22,33 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if ( + !card.includes("♠") && + !card.includes("♥") && + !card.includes("♦") && + !card.includes("♣") + ){ + return "Invalid String"; + } + const rank = card.slice(0, -1); + + if ( + !card.includes("A") && + !card.includes("J") && + !card.includes("Q") && + !card.includes("K") && + !(rank >= 2 && rank <= 10) + ) { + return "Invalid String"; + } + + if (card.includes("A")) { + return 11; + } else if (card.includes("J") || card.includes("Q") || card.includes("K")) { + return 10; + } else if (rank >= 2 && rank <= 10) { + return rank; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +66,17 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("J♠"), 10); +assertEquals(getCardValue("K♠"), 10); +assertEquals(getCardValue("Q♠"), 10); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("10♠"), 10); +assertEquals(getCardValue(" ♠"), "Invalid String"); +assertEquals(getCardValue(" 6 ♠"), "Invalid String"); +assertEquals(getCardValue(" ♠"), "Invalid String"); +assertEquals(getCardValue(" **♠"), "Invalid String"); +assertEquals(getCardValue("10 **"), "Invalid String"); // Handling invalid cards try { @@ -50,3 +87,5 @@ try { } catch (e) {} // What other invalid card cases can you think of? +// card with a mix of suit +//card with 0 at the front 01♠ From d1394c18573032c3ccdb20a6bbe5e65204160b2e Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Tue, 3 Mar 2026 00:52:42 +0000 Subject: [PATCH 4/7] Rewrite test with jest completed --- .../implement/3-get-card-value.js | 11 +++--- .../1-get-angle-type.test.js | 33 +++++++++++++++++ .../2-is-proper-fraction.test.js | 6 ++++ .../3-get-card-value.test.js | 35 +++++++++++++++++++ 4 files changed, 80 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 9fdcecbb5e..cbf1125f24 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,7 +8,7 @@ // "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" // The suit can be one of the following emojis: // "♠", "♥", "♦", "♣" -// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". +// For example: "A♠", "2♥", "10♥", "J"2♠"", "Q♦", "K♦". // When the card is an ace ("A"), the function should return 11. // When the card is a face card ("J", "Q", "K"), the function should return 10. @@ -28,7 +28,7 @@ function getCardValue(card) { !card.includes("♦") && !card.includes("♣") ){ - return "Invalid String"; + throw new Error("Invalid String"); } const rank = card.slice(0, -1); @@ -39,12 +39,12 @@ function getCardValue(card) { !card.includes("K") && !(rank >= 2 && rank <= 10) ) { - return "Invalid String"; + throw new Error("Invalid String"); } - if (card.includes("A")) { + if (rank==="A") { return 11; - } else if (card.includes("J") || card.includes("Q") || card.includes("K")) { + } else if (rank==="J" || rank==="Q" || rank==="K") { return 10; } else if (rank >= 2 && rank <= 10) { return rank; @@ -77,6 +77,7 @@ assertEquals(getCardValue(" 6 ♠"), "Invalid String"); assertEquals(getCardValue(" ♠"), "Invalid String"); assertEquals(getCardValue(" **♠"), "Invalid String"); assertEquals(getCardValue("10 **"), "Invalid String"); +assertEquals(getCardValue("A10♠"), "Invalid String"); // Handling invalid cards try { 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..accf4e8e1d 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,40 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right Angles" when(angle===90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles + +test(`should return "Obtuse angles" when (90< angle <180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); + expect(getAngleType(160)).toEqual("Obtuse angle"); + expect(getAngleType(100)).toEqual("Obtuse angle"); + expect(getAngleType(151.55)).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(270)).toEqual("Reflex angle"); + expect(getAngleType(350)).toEqual("Reflex angle"); + expect(getAngleType(359.5)).toEqual("Reflex angle"); + expect(getAngleType(210)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`Should return "Invalid angle" when (0 ==360)`, () => { + expect(getAngleType(0).toEqual("Invalid angle")); + expect(getAngleType(-1).toEqual("Invalid angle")); + expect(getAngleType(360).toEqual("Invalid angle")); + expect(getAngleType(500).toEqual("Invalid angle")); + expect(getAngleType("1e5").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..c5ef225be4 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,4 +7,10 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(1, -1)).toEqual(false); + expect(isProperFraction(10, 1)).toEqual(false); + expect(isProperFraction(1, 10)).toEqual(true); + expect(isProperFraction(-1, 0)).toEqual(true); + expect(isProperFraction(1e2, 1e4)).toEqual(true); + expect(isProperFraction(1e4, 1e0)).toEqual(false); }); 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..8781716788 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,44 @@ 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 Number from "2-10" when given a number card`,()=>{ + + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("3♠")).toEqual(3); + expect(getCardValue("4♣")).toEqual(4); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("6♠")).toEqual(6); + expect(getCardValue("7♣")).toEqual(7); + expect(getCardValue("8♠")).toEqual(8); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♠")).toEqual(10); + }) + + // Face Cards (J, Q, K) + +test(`Should return 10 when given a face card`,()=>{ + +expect(getCardValue("J♣")).toEqual(10); +expect(getCardValue("K♣")).toEqual(10); +expect(getCardValue("Q♣")).toEqual(10); +expect(getCardValue("Q♠")).toEqual(10); +expect(getCardValue("J♠")).toEqual(10); +expect(getCardValue("K♠")).toEqual(10); +}) // Invalid Cards +test('throws on Invalid String', () => { + expect(() => { getCardValue('A10♠');}).toThrow("Invalid String"); + expect(() => { getCardValue('A');}).toThrow("Invalid String"); + expect(() => { getCardValue('110♠');}).toThrow("Invalid String"); + expect(() => { getCardValue(' ♠');}).toThrow("Invalid String"); + expect(() => { getCardValue('eeeeeej1234');}).toThrow("Invalid String"); + +}); + + + // 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 815a1c815745add5c9a718417e4d3362eca4e396 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Sat, 14 Mar 2026 16:32:22 +0000 Subject: [PATCH 5/7] fixedproper fraction and card functions --- .../implement/1-get-angle-type.js | 2 +- .../implement/2-is-proper-fraction.js | 27 ++++++++---- .../implement/3-get-card-value.js | 44 +++++++++++++------ .../1-get-angle-type.test.js | 14 +++--- .../2-is-proper-fraction.test.js | 2 +- 5 files changed, 57 insertions(+), 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 4ca24a776b..a6d8d399af 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 @@ -23,7 +23,7 @@ function getAngleType(angle) { return "Obtuse angle"; } else if (angle === 90) { return "Right angle"; - } else if (angle === 180) { + } else if (angle===180) { return "Straight angle"; } else if (angle > 180 && angle < 360) { return "Reflex angle"; 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 9045271650..3b244a1574 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,10 +12,12 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function - if(numerator>denominator) { - return false - }else{ - return true + if ( Math.abs(numerator) >= Math.abs(denominator)) { + return false; + } else if (Math.abs(denominator) === 0) { + return false; + } else { + return true; } } @@ -38,10 +40,17 @@ function assertEquals(actualOutput, targetOutput) { assertEquals(isProperFraction(1, 2), true); assertEquals(isProperFraction(1, 10000), true); assertEquals(isProperFraction(100, 2), false); -assertEquals(isProperFraction(1, 0.005), false); assertEquals(isProperFraction(1e2, 1e3), true); -assertEquals(isProperFraction(1e4, 1e0), false); -assertEquals(isProperFraction(-1, 1), true); +assertEquals(isProperFraction(1e4, 1), false); +assertEquals(isProperFraction(-1, 1), false); assertEquals(isProperFraction(1, -1), false); -assertEquals(isProperFraction(0, -1), false); -assertEquals(isProperFraction(-1, 0), true); +assertEquals(isProperFraction(0, -1), true); +assertEquals(isProperFraction(-1, -2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(-1, 0), false); + + + + 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 cbf1125f24..80bf331a95 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,13 +22,16 @@ // execute the code to ensure all tests pass. function getCardValue(card) { + if (card.length >= 4) { + throw new Error ("Invalid String"); + } if ( !card.includes("♠") && !card.includes("♥") && !card.includes("♦") && !card.includes("♣") - ){ - throw new Error("Invalid String"); + ) { + throw new Error('Invalid String'); } const rank = card.slice(0, -1); @@ -42,12 +45,12 @@ function getCardValue(card) { throw new Error("Invalid String"); } - if (rank==="A") { + 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 rank; + return Number(rank); } } @@ -72,20 +75,33 @@ assertEquals(getCardValue("K♠"), 10); assertEquals(getCardValue("Q♠"), 10); assertEquals(getCardValue("2♠"), 2); assertEquals(getCardValue("10♠"), 10); -assertEquals(getCardValue(" ♠"), "Invalid String"); -assertEquals(getCardValue(" 6 ♠"), "Invalid String"); -assertEquals(getCardValue(" ♠"), "Invalid String"); -assertEquals(getCardValue(" **♠"), "Invalid String"); -assertEquals(getCardValue("10 **"), "Invalid String"); -assertEquals(getCardValue("A10♠"), "Invalid String"); + + // Handling invalid cards -try { - getCardValue("invalid"); +function throwInvalidStringError(card){ +try { + getCardValue(card) // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); -} catch (e) {} +} catch (e) { + assertEquals(e.message,"Invalid String") +} +} + +throwInvalidStringError("invalid"); +throwInvalidStringError(" ♠"); +throwInvalidStringError(" 6 ♠"); +throwInvalidStringError(" ♠"); +throwInvalidStringError(" **♠"); +throwInvalidStringError("10 **"); +throwInvalidStringError("A10♠"); +throwInvalidStringError("0x02♠"); +throwInvalidStringError("2.1♠"); +throwInvalidStringError("0002♠"); +throwInvalidStringError("22"); +throwInvalidStringError("♠2"); // What other invalid card cases can you think of? // card with a mix of suit 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 accf4e8e1d..0966e8e12b 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 @@ -30,11 +30,11 @@ test(`should return "Obtuse angles" when (90< angle <180)`, () => { // Case 4: Straight angle test(`should return "Straight angle" when (angle===180)`, () => { - expect(getAngleType(180).toEqual("Straight angle")); + expect(getAngleType(180)).toEqual("Straight angle"); }); // Case 5: Reflex angles -test(`Should return "Reflex angle" when (180>angle<360)`, () => { +test(`Should return "Reflex angle" when (360180)`, () => { expect(getAngleType(181)).toEqual("Reflex angle"); expect(getAngleType(270)).toEqual("Reflex angle"); expect(getAngleType(350)).toEqual("Reflex angle"); @@ -45,9 +45,9 @@ test(`Should return "Reflex angle" when (180>angle<360)`, () => { // Case 6: Invalid angles test(`Should return "Invalid angle" when (0 ==360)`, () => { - expect(getAngleType(0).toEqual("Invalid angle")); - expect(getAngleType(-1).toEqual("Invalid angle")); - expect(getAngleType(360).toEqual("Invalid angle")); - expect(getAngleType(500).toEqual("Invalid angle")); - expect(getAngleType("1e5").toEqual("Invalid angle")); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(500)).toEqual("Invalid angle"); + expect(getAngleType("1e5")).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 c5ef225be4..37f1b42995 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 @@ -10,7 +10,7 @@ test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, -1)).toEqual(false); expect(isProperFraction(10, 1)).toEqual(false); expect(isProperFraction(1, 10)).toEqual(true); - expect(isProperFraction(-1, 0)).toEqual(true); + expect(isProperFraction(-1, 0)).toEqual(false); expect(isProperFraction(1e2, 1e4)).toEqual(true); expect(isProperFraction(1e4, 1e0)).toEqual(false); }); From 865cf0939165497a0d6b895f483bc154b196addf Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Mon, 16 Mar 2026 09:34:49 +0000 Subject: [PATCH 6/7] seperated suit and refactor function --- .../implement/2-is-proper-fraction.js | 16 ++-- .../implement/3-get-card-value.js | 73 +++++++++++-------- .../1-get-angle-type.test.js | 2 +- .../2-is-proper-fraction.test.js | 14 ++-- .../3-get-card-value.test.js | 49 +++++++------ 5 files changed, 82 insertions(+), 72 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 3b244a1574..cb886e328a 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 @@ -9,16 +9,16 @@ // 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 isProperFraction(numerator, denominator) { - // TODO: Implement this function - if ( Math.abs(numerator) >= Math.abs(denominator)) { + if (denominator === 0) { return false; - } else if (Math.abs(denominator) === 0) { + } + + if (Math.abs(numerator) >= Math.abs(denominator)) { return false; - } else { - return true; } + + return true; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -50,7 +50,3 @@ assertEquals(isProperFraction(1, -2), true); assertEquals(isProperFraction(-1, 2), true); assertEquals(isProperFraction(1, 0), false); assertEquals(isProperFraction(-1, 0), false); - - - - 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 80bf331a95..be008520d0 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,36 +22,44 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if (card.length >= 4) { - throw new Error ("Invalid String"); - } - if ( - !card.includes("♠") && - !card.includes("♥") && - !card.includes("♦") && - !card.includes("♣") - ) { - throw new Error('Invalid String'); - } - const rank = card.slice(0, -1); - if ( - !card.includes("A") && - !card.includes("J") && - !card.includes("Q") && - !card.includes("K") && - !(rank >= 2 && rank <= 10) + typeof card !== "string" || + card.length < 2 || + card.length > 3 || + card.includes(" ") ) { - throw new Error("Invalid String"); + throw new Error("Invalid string"); } - if (rank === "A") { + const suit = card.slice(-1); + const rank = card.slice(0, -1); + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = [ + "A", + "J", + "Q", + "K", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + ]; + + if (!validSuits.includes(suit) || !validRanks.includes(rank)) { + throw new Error("Invalid string"); + } else if (rank === "A") { return 11; } else if (rank === "J" || rank === "Q" || rank === "K") { return 10; - } else if (rank >= 2 && rank <= 10) { + } else if (rank) { return Number(rank); } + throw new Error("Invalid string"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -76,18 +84,15 @@ assertEquals(getCardValue("Q♠"), 10); assertEquals(getCardValue("2♠"), 2); assertEquals(getCardValue("10♠"), 10); - - // Handling invalid cards -function throwInvalidStringError(card){ - -try { - getCardValue(card) - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card"); -} catch (e) { - assertEquals(e.message,"Invalid String") -} +function throwInvalidStringError(card) { + try { + getCardValue(card); + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card"); + } catch (e) { + assertEquals(e.message, "Invalid string"); + } } throwInvalidStringError("invalid"); @@ -102,6 +107,10 @@ throwInvalidStringError("2.1♠"); throwInvalidStringError("0002♠"); throwInvalidStringError("22"); throwInvalidStringError("♠2"); +throwInvalidStringError("2 ♠"); +throwInvalidStringError("2.♠"); +throwInvalidStringError("+2♠"); +throwInvalidStringError("♠A"); // What other invalid card cases can you think of? // card with a mix of suit 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 0966e8e12b..8074f3161d 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 @@ -34,7 +34,7 @@ test(`should return "Straight angle" when (angle===180)`, () => { }); // Case 5: Reflex angles -test(`Should return "Reflex angle" when (360180)`, () => { +test(`Should return "Reflex angle" when (angle > 180 && angle < 360)`, () => { expect(getAngleType(181)).toEqual("Reflex angle"); expect(getAngleType(270)).toEqual("Reflex angle"); expect(getAngleType(350)).toEqual("Reflex 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 37f1b42995..a6dc16b2e2 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,12 +5,14 @@ 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(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, -4)).toEqual(true); + expect(isProperFraction(0, 1)).toEqual(true); +}); +test("should return false when denominator is zero", () => { expect(isProperFraction(1, 0)).toEqual(false); - expect(isProperFraction(1, -1)).toEqual(false); - expect(isProperFraction(10, 1)).toEqual(false); - expect(isProperFraction(1, 10)).toEqual(true); + expect(isProperFraction(10, 0)).toEqual(false); + expect(isProperFraction(-2, 0)).toEqual(false); expect(isProperFraction(-1, 0)).toEqual(false); - expect(isProperFraction(1e2, 1e4)).toEqual(true); - expect(isProperFraction(1e4, 1e0)).toEqual(false); + expect(isProperFraction(1, 0)).toEqual(false); }); 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 8781716788..1d6d0226b7 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,8 +11,7 @@ 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 Number from "2-10" when given a number card`,()=>{ - +test(`should return Number from "2-10" when given a number card`, () => { expect(getCardValue("2♠")).toEqual(2); expect(getCardValue("3♠")).toEqual(3); expect(getCardValue("4♣")).toEqual(4); @@ -22,34 +21,38 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("8♠")).toEqual(8); expect(getCardValue("9♠")).toEqual(9); expect(getCardValue("10♠")).toEqual(10); - }) - +}); // Face Cards (J, Q, K) -test(`Should return 10 when given a face card`,()=>{ - -expect(getCardValue("J♣")).toEqual(10); -expect(getCardValue("K♣")).toEqual(10); -expect(getCardValue("Q♣")).toEqual(10); -expect(getCardValue("Q♠")).toEqual(10); -expect(getCardValue("J♠")).toEqual(10); -expect(getCardValue("K♠")).toEqual(10); -}) +test(`Should return 10 when given a face card`, () => { + expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); + expect(getCardValue("Q♣")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}); // Invalid Cards -test('throws on Invalid String', () => { - expect(() => { getCardValue('A10♠');}).toThrow("Invalid String"); - expect(() => { getCardValue('A');}).toThrow("Invalid String"); - expect(() => { getCardValue('110♠');}).toThrow("Invalid String"); - expect(() => { getCardValue(' ♠');}).toThrow("Invalid String"); - expect(() => { getCardValue('eeeeeej1234');}).toThrow("Invalid String"); - +test("throws on Invalid String", () => { + expect(() => { + getCardValue("A10♠"); + }).toThrow("Invalid string"); + expect(() => { + getCardValue("A"); + }).toThrow("Invalid string"); + expect(() => { + getCardValue("110♠"); + }).toThrow("Invalid string"); + expect(() => { + getCardValue(" ♠"); + }).toThrow("Invalid string"); + expect(() => { + getCardValue("eeeeeej1234"); + }).toThrow("Invalid string"); }); - - // 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 b1a1d5ec7b3baa24553a26ee94c6ec910d7681f2 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Fri, 20 Mar 2026 09:38:11 +0000 Subject: [PATCH 7/7] refactor getCard function and add more test case --- .../implement/3-get-card-value.js | 10 ++-------- .../2-is-proper-fraction.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 8 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 be008520d0..f2a4fa4359 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,12 +22,7 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if ( - typeof card !== "string" || - card.length < 2 || - card.length > 3 || - card.includes(" ") - ) { + if (typeof card !== "string") { throw new Error("Invalid string"); } @@ -56,10 +51,9 @@ function getCardValue(card) { return 11; } else if (rank === "J" || rank === "Q" || rank === "K") { return 10; - } else if (rank) { + } else { return Number(rank); } - throw new Error("Invalid string"); } // The line below allows us to load the getCardValue function into tests in other files. 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 a6dc16b2e2..f8a2713c1f 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 @@ -16,3 +16,21 @@ test("should return false when denominator is zero", () => { expect(isProperFraction(-1, 0)).toEqual(false); expect(isProperFraction(1, 0)).toEqual(false); }); + +test("should return false when denominator and numerator have both the same negative and positive integer", () => { + expect(isProperFraction(-1, 1)).toEqual(false); + expect(isProperFraction(1, -1)).toEqual(false); +}); + +test(`should return true when denominator is > numerator `, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(1, 10000)).toEqual(true); + + expect(isProperFraction(1e2, 1e3)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); +}); + +test("should return false when denominator < numerator", () => { + expect(isProperFraction(1e4, 1)).toEqual(false); + expect(isProperFraction(100, 2)).toEqual(false); +});