From a97de34d4d5cb0d225fc5c370afcc3c2c37810bb Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Wed, 23 Sep 2026 20:34:13 +0100 Subject: [PATCH 1/6] 1-get-angle-type.js completed --- .../implement/1-get-angle-type.js | 32 ++++++++++++++++++- 1 file changed, 31 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..a245bfe749 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 < 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. @@ -35,3 +47,21 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(78); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(102); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(250); +assertEquals(reflex, "Reflex angle"); + +const invalid = getAngleType(420); +assertEquals(invalid, "Invalid angle"); + +const zero = getAngleType(0); +assertEquals(zero, "Invalid angle"); From 9b3b9f67d2f3df47eae416a309f464337a9cae5d Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Thu, 24 Sep 2026 10:48:41 +0100 Subject: [PATCH 2/6] 2-is-proper-function.js completed --- .../implement/2-is-proper-fraction.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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..e140374bb5 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,15 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + // Non-unit fractions have a numerator that is more than 1, but less than the denominator. + //Unit fractions all have a numerator of 1. + + let validFraction = numerator < denominator && numerator > 0; + if (validFraction) { + return true; + } else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +39,9 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 5), true); +assertEquals(isProperFraction(0, 4), false); +assertEquals(isProperFraction(5, 5), false); +assertEquals(isProperFraction(6, 5), false); +assertEquals(isProperFraction(3, 5), true); +assertEquals(isProperFraction(1, 0), false); From c017a05d6608fae81309aff68b6ab8a4aef190fc Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Thu, 24 Sep 2026 12:35:29 +0100 Subject: [PATCH 3/6] 3-get-card-value.js completed --- .../implement/3-get-card-value.js | 50 ++++++++++++++++++- 1 file changed, 49 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 ff5c532e1d..14147f7f3b 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,21 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + let regex = /^([2-9]|10|[AJQK])[♠♥♣♦]$/; + const valid = regex.test(card); + if (!valid) { + throw new Error("Invalid card"); + } + let rank = card.slice(0, -1); + + if (rank === "A") { + return 11; + } else if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } else { + rank = Number(rank); + return rank; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +54,12 @@ 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("10♥"), 10); +assertEquals(getCardValue("2♥"), 2); +assertEquals(getCardValue("K♠"), 10); +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♦"), 10); // Handling invalid cards try { @@ -52,3 +72,31 @@ try { } // What other invalid card cases can you think of? + +try { + getCardValue(3); + console.error("Error was not thrown for number 3"); +} catch (e) { + console.log("Error thrown for invalid format"); +} + +try { + getCardValue("11K♠"); + console.error("Error format too long"); +} catch (e) { + console.log("Error thrown for too many characters"); +} + +try { + getCardValue(-1); + console.error("Error for negative number"); +} catch (e) { + console.log("Error thrown for negative number"); +} + +try { + getCardValue("22♥"); + console.error("Error for string 22♥"); +} catch (e) { + console.log("Error thrown for string 22♥"); +} From fff67366ad3a9a7bf6cd17b27e016189f5dadff5 Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Thu, 24 Sep 2026 13:16:26 +0100 Subject: [PATCH 4/6] 1-get-angle-type.test.js completed --- .../1-get-angle-type.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..344722f6b0 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 @@ -10,11 +10,37 @@ 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(77)).toEqual("Acute angle"); + expect(getAngleType(24)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); // 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(133)).toEqual("Obtuse angle"); + expect(getAngleType(111)).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(359)).toEqual("Reflex angle"); + expect(getAngleType(199)).toEqual("Reflex angle"); + expect(getAngleType(244)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle"`, () => { + expect(getAngleType(361)).toEqual("Invalid angle"); + expect(getAngleType(2332)).toEqual("Invalid angle"); + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType("-222r")).toEqual("Invalid angle"); +}); From ca55531072520ec20173abb0914e1dbf2b9e6e5a Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Thu, 24 Sep 2026 14:25:52 +0100 Subject: [PATCH 5/6] 2-is-proper-fraction.test.js completed --- .../2-is-proper-fraction.test.js | 28 +++++++++++++++++++ 1 file changed, 28 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 7f087b2ba1..8244a758a9 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,6 +5,34 @@ 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`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +test(`should return true when input (1, 2)`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); +test(`should return false when (numerator = 0)`, () => { + expect(isProperFraction(0, 4)).toEqual(false); +}); +test(`should return false when (numerator===denominator)`, () => { + expect(isProperFraction(5, 5)).toEqual(false); +}); +test(`should return false when (numerator>denominator)`, () => { + expect(isProperFraction(6, 5)).toEqual(false); +}); +test(`should return false when (numerator ===0 && denominator === 0)`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); +test(`should return false when numerator is negative number`, () => { + expect(isProperFraction(-4, 8)).toEqual(false); +}); +test(`should return false when (negative numerator === denominator )`, () => { + expect(isProperFraction(-5, 5)).toEqual(false); +}); +test(`should return false when ( numerator < negative denominator )`, () => { + expect(isProperFraction(3, -5)).toEqual(false); +}); +test(`should return false when numerator is zero and denominator is negative zero`, () => { + expect(isProperFraction(0, -0)).toEqual(false); +}); From 0681a404c26d0580525a4e2987972e29b0bafb00 Mon Sep 17 00:00:00 2001 From: bartoszkawiak Date: Thu, 24 Sep 2026 15:24:20 +0100 Subject: [PATCH 6/6] 3-get-card-value.test.js completed --- .../3-get-card-value.test.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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..6700235651 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,10 +11,36 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +let suits = ["♠", "♥", "♣", "♦"]; +for (let number = 2; number <= 10; number++) { + for (let suit of suits) { + test(`should return card value as number`, () => { + expect(getCardValue(`${number}${suit}`)).toEqual(number); + }); + } +} // Face Cards (J, Q, K) + +let chars = ["J", "Q", "K"]; + +for (let char of chars) { + for (let suit of suits) { + test(`should return card value as 10`, () => { + expect(getCardValue(`${char}${suit}`)).toEqual(10); + }); + } +} // Invalid Cards +let invalidCards = ["22♥", "11K♠", -1, 3, "11^♠"]; +for (let card of invalidCards) { + test(`should return "Invalid card"`, () => { + expect(() => { + getCardValue(card); + }).toThrow(); + }); +} + // 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 -