From 0cbad6b057f907bdda30f16228b4b0cd341fe7ef Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sun, 8 Mar 2026 15:59:00 +0000 Subject: [PATCH 1/7] implemented and tested the function in 1-get-angle-type.js file --- .../implement/1-get-angle-type.js | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e..37de9f494 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 === 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 if (angle > 180 && angle < 360) { + return "Reflex angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -31,7 +43,30 @@ function assertEquals(actualOutput, 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"); +// Invalid angles +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(-10), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); + +// Acute angles and its boundaries +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89), "Acute angle"); + +// Right angle +assertEquals(getAngleType(90), "Right angle"); + +// Obtuse angles and its boundaries +assertEquals(getAngleType(91), "Obtuse angle"); +assertEquals(getAngleType(120), "Obtuse angle"); +assertEquals(getAngleType(179), "Obtuse angle"); + +// Straight angle +assertEquals(getAngleType(180), "Straight angle"); + +// Reflex angles and its boundaries +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(200), "Reflex angle"); +assertEquals(getAngleType(359), "Reflex angle"); + + From 1b26097997a2ab56cfd851331e6bb4ffff1fac14 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sun, 8 Mar 2026 20:07:00 +0000 Subject: [PATCH 2/7] impelemented and tested proper fraction function --- .../implement/2-is-proper-fraction.js | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b64..a06f5adbd 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,7 +11,8 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + const properFraction = numerator / denominator; + return properFraction > 0 && properFraction < 1; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -26,8 +27,27 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? -// Example: 1/2 is a proper fraction +// TEST CASES +// Normal Scenarios assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(5, 10), true); + +// Boundary Values +assertEquals(isProperFraction(0, 5), false); +assertEquals(isProperFraction(1, 1), false); + +// Improper Fraction +assertEquals(isProperFraction(8, 3), false) + +// Negative Values +assertEquals(isProperFraction(-3, 8), false); +assertEquals(isProperFraction(-8, -3), false); +assertEquals(isProperFraction(-3, -8), true); + +//Very Small +assertEquals(isProperFraction(0.0001, 999999), true); + +//Very Large +assertEquals(isProperFraction(999999, 0.0001), false); + From 0db84518c1b9a8ad926a0582001741eb6ff82418 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Tue, 10 Mar 2026 19:29:17 +0000 Subject: [PATCH 3/7] implemented and tested getCardValue function in 3-get-card-value.js --- .../implement/3-get-card-value.js | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index c7559e787..124045aa9 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,10 +22,48 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const rankList = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + const suitList = ["♠", "♥", "♦", "♣"]; + + const faceCard = rankList.slice(-3); + + const cardRank = card.slice(0, -1); + const cardSuit = card.charAt(card.length - 1); + + const validCard = rankList.includes(cardRank) && suitList.includes(cardSuit); + + if (!validCard) { + throw new Error("Invalid card"); + } + + if (cardRank === "A") { + return 11; + } + + if (faceCard.includes(cardRank)) { + return 10; + } + + return Number(cardRank); } -// The line below allows us to load the getCardValue function into tests in other files. +console.log(getCardValue("J♥")); + +// The line below allows us to load the getCard Value function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getCardValue; @@ -37,9 +75,11 @@ 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("K♦"), 10); +assertEquals(getCardValue("10♣"), 10); // Handling invalid cards try { @@ -49,4 +89,19 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} + // What other invalid card cases can you think of? +try { + getCardValue("♠9"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("♠"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} From 4f46450d425d3f127e1a79959bb841d0f25ce539 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Tue, 10 Mar 2026 20:07:45 +0000 Subject: [PATCH 4/7] write jest test cases for getAngleType function --- .../1-get-angle-type.test.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 d777f348d..dd35b27ba 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 @@ -2,7 +2,7 @@ // 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, +//Write tests in Jest syntax to cover all cases/outcomes, // including boundary and invalid cases. // Case 1: Acute angles @@ -14,7 +14,33 @@ 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 (angle > 90 && angle < 180)', () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).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 (angle > 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 || angle >= 360)', () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); +}); From 4b897f519bde5aeaaa47bb956adcba6f3800b7a0 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Tue, 10 Mar 2026 20:19:22 +0000 Subject: [PATCH 5/7] write jest test cases for isProperFraction function --- .../2-is-proper-fraction.test.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 7f087b2ba..ec09ba445 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 @@ -2,9 +2,35 @@ // We will use the same function, but write tests for it using Jest in this file. 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. +// 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`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// Normal case: +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(5, 10)).toEqual(true); +}); +// Boundary Value +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(1, 0)).toEqual(false); +}); +// Improper Fraction +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(1, 1)).toEqual(false); +}); +// Negative Value +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(-3, 8)).toEqual(false); + +}); +// Very Small +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(0.0001, 999999)).toEqual(true); +}); +// very large +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(999999, 0.0001)).toEqual(false); +}); \ No newline at end of file From 5eb49c796b953aeb214877976239e51ba7dcaf12 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Tue, 10 Mar 2026 20:37:10 +0000 Subject: [PATCH 6/7] updated test case for proper fraction function --- .../2-is-proper-fraction.test.js | 16 ++++++++-------- .../3-get-card-value.test.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 9 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 ec09ba445..473e94001 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,27 +10,27 @@ test(`should return false when denominator is zero`, () => { }); // Normal case: -test(`should return false when denominator is zero`, () => { +test(`should return true in normal scenario`, () => { expect(isProperFraction(5, 10)).toEqual(true); }); // Boundary Value -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); +test(`should return false when numerator is 0`, () => { + expect(isProperFraction(0, 5)).toEqual(false); }); // Improper Fraction -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 1)).toEqual(false); +test(`should return false when numerator is greater than denominator`, () => { + expect(isProperFraction(8, 3)).toEqual(false); }); // Negative Value -test(`should return false when denominator is zero`, () => { +test(`should return false when numerator is negative`, () => { expect(isProperFraction(-3, 8)).toEqual(false); }); // Very Small -test(`should return false when denominator is zero`, () => { +test(`should return true with very small values`, () => { expect(isProperFraction(0.0001, 999999)).toEqual(true); }); // very large -test(`should return false when denominator is zero`, () => { +test(`should return false with very large`, () => { expect(isProperFraction(999999, 0.0001)).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 cf7f9dae2..e036c7963 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,7 +2,7 @@ // 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. +// Write tests in Jest syntax to cover all possible outcomes. // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { @@ -11,8 +11,17 @@ 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 11 when given an ace card`, () => { + expect(getCardValue("A♠")).toEqual(11); +}); // Face Cards (J, Q, K) +test(`Should return 11 when given an ace card`, () => { + expect(getCardValue("A♠")).toEqual(11); +}); // Invalid Cards +test(`Should return 11 when given an ace card`, () => { + expect(getCardValue("A♠")).toEqual(11); +}); // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 06520c49bd6c9a0a8cd1f506674fdd790fed9254 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Tue, 10 Mar 2026 21:00:45 +0000 Subject: [PATCH 7/7] wrote jest test cases for getCardValue function --- .../3-get-card-value.test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 e036c7963..56a3f647b 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,16 +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 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); +test(`Should return should return its numeric value`, () => { + expect(getCardValue("9♠")).toEqual(9); }); // Face Cards (J, Q, K) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); +test(`Should return 10`, () => { + expect(getCardValue("K♠")).toEqual(10); }); // Invalid Cards -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); +test(`Should throw an error`, () => { + expect(() => { + getCardValue("♠9"); + }).toThrow(); +}); +test(`Should throw an error`, () => { + expect(() => { + getCardValue("♠"); + }).toThrow(); }); // To learn how to test whether a function throws an error as expected in Jest,