From 1f89522c464db8c383a37d83f673eafa14edf58d Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 18 Feb 2026 21:36:40 +0000 Subject: [PATCH 1/6] Completed 1-get-angle-type.js exercise --- .../implement/1-get-angle-type.js | 48 +++++++++++++++++++ 1 file changed, 48 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 9e05a871e..b70ab3148 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,21 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { + // Returns the type of angle based on the number of degrees given. // 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 +49,37 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Case 2: Identify Acute Angles +// When the angle is between 0 and 90 degrees, +// then should return "Acute angle" +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Case 3: Identify Obtuse Angles +// When the angle is between 90 and 180 degrees, +// then should return "Obtuse angle" +const obtuse = getAngleType(135); +assertEquals(obtuse, "Obtuse angle"); + +// Case 4: Identify Straight Angles +// When the angle is exactly 180 degrees, +// then should return "Straight angle" +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Case 5: Identify Reflex Angles +// When the angle is between 180 and 360 degrees, +// then should return "Reflex angle" +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +// Case 6: Identify Invalid Angles +// When the angle is negative or 360+ +// then should return "Invalid angle" + +const invalid1 = getAngleType(-30); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType(400); +assertEquals(invalid2, "Invalid angle"); \ No newline at end of file From ac02de3dc421e6529dbb1079cdd8270a5eaa0ce1 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 18 Feb 2026 22:32:23 +0000 Subject: [PATCH 2/6] Completed 2-is-proper-fraction.js exercise --- .../implement/2-is-proper-fraction.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) 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..45dcd2d00 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,13 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator <= 0) { + return false; // not a valid fraction + } + if (numerator < denominator && numerator >= 0) { + return true; + } + return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +38,42 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Example: 3/5 is a postive proper fraction +const properFraction = isProperFraction(3, 5); +assertEquals(properFraction, true); + +// Example: 0/4 is a proper fraction with zero numerator +// Zero numerator is allowed in proper fractions +const zeroNumerator = isProperFraction(0, 4); +assertEquals(zeroNumerator, true); + +// Example: 7/7 is an improper fraction, +// numerator equals denominator +const equalFraction = isProperFraction(7, 7); +assertEquals(equalFraction, false); + +// Example: 8/3 is an improper fraction, +// numerator is larger +const numeratorLarger = isProperFraction(8, 3); +assertEquals(numeratorLarger, false); + +// Example: 5/0 is an invalid fraction +// Division by zero is not a valid fraction +const zeroDenominator = isProperFraction(5, 0); +assertEquals(zeroDenominator, false); + +// Example: 2/-6 is an invalid fraction +// Negative denominator makes fraction invalid +const negativeDenominator = isProperFraction(2, -6); +assertEquals(negativeDenominator, false); + +// Example: -1/4 is an invalid fraction +// Negative numerator makes fraction negative +const negativeNumerator = isProperFraction(-1, 4); +assertEquals(negativeNumerator, false); + +// Example: 1/100 is a positive fraction +// Small numerator with large denominator +const smallFraction = isProperFraction(1, 100); +assertEquals(smallFraction, true); \ No newline at end of file From b50834e97f6759f03f1a83f6b83480bcce108c5d Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Thu, 19 Feb 2026 23:50:32 +0000 Subject: [PATCH 3/6] Completed 3-get-card-value.js exercise --- .../implement/3-get-card-value.js | 76 +++++++++++++++++++ 1 file changed, 76 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 c7559e787..1d65a59ee 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 @@ -23,6 +23,31 @@ function getCardValue(card) { // TODO: Implement this function + // Checks that input is a string and has correct length, + // 2 chars for 2-9/A/J/Q/K, 3 chars for 10 + if (typeof card !== 'string' || (card.length !== 2 && card.length !==3)) { + throw new Error('Invalid card format'); + } + // Get the suit, always the last character + const suit = card.slice(-1); + // Get the rank, everything except the last character + const rank = card.slice(0, -1); + // Checks if suit is one of the four allowed symbols + if (!'♠♥♦♣'.includes(suit)) { + throw new Error('Invalid suit'); + } + // Special case: Ace is worth 11 + if (rank === 'A') return 11; + // Special case: Face cards (Jack, Queen, King) are worth 10 + if (rank === 'J' || rank === 'Q' || rank === 'K') return 10; + // For number cards (2-10): converts rank string into number + const value = Number(rank); + // Makes sure it's actually a valid number between 2 and 10 + if (isNaN(value) || value < 2 || value > 10) { + throw new Error('Invalid rank'); + } + // Return the numeric value for 2-10 + return value; } // The line below allows us to load the getCardValue function into tests in other files. @@ -41,7 +66,29 @@ function assertEquals(actualOutput, targetOutput) { // Examples: assertEquals(getCardValue("9♠"), 9); +// Valid number cards (2-10) +const twoofHearts = getCardValue("2♥"); +assertEquals(twoofHearts, 2); + +const fiveofDiamonds = getCardValue("5♦"); +assertEquals(fiveofDiamonds, 5); + +// Ace returns 11 +const aceofSpades = getCardValue("A♠"); +assertEquals(aceofSpades, 11); + +// Face cards return 10 (J, Q, K) +const jackofHearts = getCardValue("J♥"); +assertEquals(jackofHearts, 10); + +const queenofDiamonds = getCardValue("Q♦"); +assertEquals(queenofDiamonds, 10); + +const kingofClubs = getCardValue("K♣"); +assertEquals(kingofClubs, 10); + // Handling invalid cards +// Invalid format, random string try { getCardValue("invalid"); @@ -50,3 +97,32 @@ try { } catch (e) {} // What other invalid card cases can you think of? +// Too short, missing suit +try { + getCardValue("A"); + console.error("Error was not thrown for too short card"); +} catch (e) {} + +// Invalid rank +try { + getCardValue("X♠"); + console.error("Error was not thrown for invalid rank"); +} catch (e) {} + +// Invalid suit, wrong symbol +try { + getCardValue("Kx"); + console.error("Error was not thrown for missing suit"); +} catch (e) {} + +// Missing suit +try { + getCardValue("10"); + console.error("Error was not thrown for missing suit"); +} catch (e) {} + +// Empty string +try { + getCardValue(""); + console.error("Error was not thrown for empty string"); +} catch (e) {} \ No newline at end of file From f09ba97ccf0f40596a979c9b59c5055ea4c6f45f Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Fri, 20 Feb 2026 03:21:29 +0000 Subject: [PATCH 4/6] Rewrited tests for 1-get-angle-type.test.js using Jest syntax --- .../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 d777f348d..7148971cf 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,33 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is exactly 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle 180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(135)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when angle is exactly 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(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" when angle (<= 0 or >= 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-30)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); From d4ace42fc4d9663b9542eb7a9bc71dc25b59bba4 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Fri, 20 Feb 2026 03:53:13 +0000 Subject: [PATCH 5/6] Rewrote tests for 2-is-proper-fraction.test.js using Jest syntax --- .../2-is-proper-fraction.test.js | 42 ++++++++++++++++++- 1 file changed, 41 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..2ed5e5bec 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -4,7 +4,47 @@ 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 +// Special case: denominator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// Special case: numerator is zero +test(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, 4)).toEqual(true); +}); + +// Special case: numerator equals denominator +test(`should return false when numerator equals denominator`, () => { + expect(isProperFraction(7, 7)).toEqual(false); +}); + +// Special case: numerator is smaller than denominator +test(`should return true when numerator is smaller than denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +// Special case: positive proper fraction +test(`should return true for positive proper fraction`, () => { + expect(isProperFraction(3, 5)).toEqual(true); +}); + +// Special case: numerator is larger than denominator +test(`should return false when numerator is larger than denominator`, () => { + expect(isProperFraction(8, 3)).toEqual(false); +}); + +// Special case: negative denominator +test(`should return false when denominator is negative`, () => { + expect(isProperFraction(2, -6)).toEqual(false); +}); + +// Special case: negative numerator +test(`should return false when numerator is negative`, () => { + expect(isProperFraction(-1, 4)).toEqual(false); +}); + +// Special case: small positive proper fraction +test(`should return true for small positive proper fraction`, () => { + expect(isProperFraction(1, 100)).toEqual(true); +}); From ab9acf24a067ab63750d7f9af8604dd1197ce7fe Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Fri, 20 Feb 2026 04:37:32 +0000 Subject: [PATCH 6/6] Rewrote tests for 3-get-card-value.test.js using Jest syntax --- .../3-get-card-value.test.js | 30 ++++++++++++++++++- 1 file changed, 29 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 cf7f9dae2..e05b88f6d 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 @@ -14,7 +14,35 @@ test(`Should return 11 when given an ace card`, () => { // Face Cards (J, Q, K) // Invalid Cards +// Case 2: Number Cards (2-10) +test(`Should return correct value for single digit number card`, () => { + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("5♦")).toEqual(5); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: Face cards (J, Q, K) +test(`Should return 10 for face cards (J, Q, K)`, () => { + expect(getCardValue("J♥")).toEqual(10); + expect(getCardValue("Q♦")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); +}); + +// Case 4: Invalid Cards +test(`Should throw error for invalid cards`, () => { + expect(() => getCardValue("invalid")).toThrow(); + // too short + expect(() => getCardValue("A")).toThrow(); + // invalid rank + expect(() => getCardValue("X♠")).toThrow(); + // invalid suit + expect(() => getCardValue("Kx")).toThrow(); + // missing suit + expect(() => getCardValue("10")).toThrow(); + // empty string + expect(() => getCardValue("")).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 -