From f67441c2872a5816982d973f9575636d66995086 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Thu, 19 Feb 2026 17:39:14 +0000 Subject: [PATCH 1/9] completed exercise and test has passed with no errors 1-get-angle-type.js --- .../implement/1-get-angle-type.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 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..5582cd0019 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 @@ -14,10 +14,31 @@ // 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) { - // TODO: Implement this function +function getAngleType(angle){ + if(angle < 90){ + return "Acute angle"; + } + if(angle === 90){ + return "Right angle"; + } + + if(angle > 90 && angle< 180){ + return "Obtuse"; + } + + if(angle === 180){ + return "Straight angle"; + } + + if(angle > 180 && angle <360){ + return "Reflex angle"; + } + return " Invalid angle found" } + // TODO: Implement this function + + // 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; From d28e5cef784ee39cbeb2db41645e4d048c4312c6 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Fri, 20 Feb 2026 20:41:14 +0000 Subject: [PATCH 2/9] completed exercise 1-get-angle-type-test.js and 1-get-angle-type.js. Completed the invalid cases and completed the test using Jest --- .../implement/1-get-angle-type.js | 36 +++++++++++++++--- .../1-get-angle-type.test.js | 38 +++++++++++++++++-- 2 files changed, 66 insertions(+), 8 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 5582cd0019..7695a3895c 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,27 +15,28 @@ // execute the code to ensure all tests pass. function getAngleType(angle){ - if(angle < 90){ + if(angle >0 && angle <90){ return "Acute angle"; } if(angle === 90){ return "Right angle"; } - if(angle > 90 && angle< 180){ - return "Obtuse"; + if(angle >90 && angle <180){ + return "Obtuse angle"; } if(angle === 180){ return "Straight angle"; } - if(angle > 180 && angle <360){ + if(angle >180 && angle <360){ return "Reflex angle"; } - return " Invalid angle found" + return "Invalid angle found" } + // TODO: Implement this function @@ -56,3 +57,28 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(60); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(160); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(275); +assertEquals(reflex, "Reflex angle"); +// test invalid cases + +const invalidAngleCase1 = getAngleType (0); +assertEquals(invalidAngleCase1, "Invalid angle found"); + +const invalidAngleCase2 = getAngleType (-15); +assertEquals(invalidAngleCase2, "Invalid angle found"); + +const invalidAngleCase3 = getAngleType (360); +assertEquals(invalidAngleCase3, "Invalid angle found"); + +const invalidAngleCase4 = getAngleType (400); +assertEquals(invalidAngleCase4, "Invalid angle found"); \ No newline at end of file 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..ca388c0509 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,16 +5,48 @@ const getAngleType = require("../implement/1-get-angle-type"); // TODO: Write tests in Jest syntax to cover all cases/outcomes, // including boundary and invalid cases. +// Test various acute angles, including boundary cases // Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases +// When angle is greater that 0 and less than 90 +test(`should return "Acute angle" when (angle >0 angle < 90)`, () => { expect(getAngleType(1)).toEqual("Acute angle"); expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); -// Case 2: Right angle +// Case 2: Right angles +// When angle is 90 +test(`should return "Right angle" when (angle = 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +// When angle is greater that 90 and less than 180 +test(`should return "Obtuse angle" when (angle >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 +// When angle is 180 +test(`should return "Straight angle" when (angle = 180)`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +// When angle is greater that 180 and less than 360 +test(`should return "Reflex angle" when (angle >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 +// When angle is equal to or less than 0 and is equal to or greater than 360 +test(`should return "Invalid angle found" when (angle <= 0 or angle >= 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle found"); + expect(getAngleType(-1)).toEqual("Invalid angle found"); + expect(getAngleType(360)).toEqual("Invalid angle found"); + expect(getAngleType(520)).toEqual("Invalid angle found"); +}); From e8ca8300694821bd01bd5b4de086891b5cd4bf0a Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Fri, 20 Feb 2026 22:26:16 +0000 Subject: [PATCH 3/9] Completed exercise 2-is-proper-fraction.js and 2-is-proper-fraction-test.js and updated test in 1-get-angle-type.test.js --- .../implement/2-is-proper-fraction.js | 21 ++++++++++++++++--- .../1-get-angle-type.test.js | 8 +++---- .../2-is-proper-fraction.test.js | 17 +++++++++++++++ 3 files changed, 39 insertions(+), 7 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 970cb9b641..789254765f 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 @@ -10,9 +10,19 @@ // 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 -} + function isProperFraction(numerator, denominator) { + // Denominator cannot be 0 + if (denominator === 0) + return false; + if (!Number.isFinite(numerator) || !Number.isFinite(denominator)){ + return false; + } + if (!Number.isInteger(numerator) || !Number.isInteger(denominator)){ + return false; + } + //if is less than + return Math.abs(numerator) < Math.abs(denominator); + } // 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. @@ -31,3 +41,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(-1, -2), true); +assertEquals(isProperFraction("1", 2), false); +assertEquals(isProperFraction(1, 0), false); + 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 ca388c0509..7148cb5d05 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 @@ -9,14 +9,14 @@ const getAngleType = require("../implement/1-get-angle-type"); // Case 1: Acute angles // When angle is greater that 0 and less than 90 test(`should return "Acute angle" when (angle >0 angle < 90)`, () => { - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(1)).toEqual("Acute angle"); + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(89)).toEqual("Acute angle"); }); // Case 2: Right angles // When angle is 90 -test(`should return "Right angle" when (angle = 90)`, () => { +test(`should return Right angle when (angle = 90)`, () => { expect(getAngleType(90)).toEqual("Right 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..ed77c6ced9 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,20 @@ 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 denominator is greater than numerator (2)`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +test(`should return false when denominator is smaller than the numerator (1)`, () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); + +test(`should return true when both values are valid numbers`, () => { + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +test(`should return false when a number is not an integer`, () => { + expect(isProperFraction("1", 2)).toEqual(false); +}); + From 5cd25f57871b175b2600708c792e3b4a080d5d8c Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Sun, 22 Feb 2026 19:40:27 +0000 Subject: [PATCH 4/9] Completed exercise 2-is-proper-fraction.js and 2-is-proper-fraction-test.js updated code and test --- .../implement/2-is-proper-fraction.js | 22 ++++------ .../implement/3-get-card-value.js | 42 ++++++++++++++++++- .../2-is-proper-fraction.test.js | 7 +--- 3 files changed, 50 insertions(+), 21 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 789254765f..bc33e2dda3 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,18 +11,14 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // Denominator cannot be 0 - if (denominator === 0) - return false; - if (!Number.isFinite(numerator) || !Number.isFinite(denominator)){ - return false; - } - if (!Number.isInteger(numerator) || !Number.isInteger(denominator)){ - return false; - } - //if is less than - return Math.abs(numerator) < Math.abs(denominator); - } + // Denominator cannot be 0 because it won't make a fraction. + if (denominator === 0) { + return false; + } + // Compare absolute values to eliminate negative values + //Proper fraction = absolute value of numerator < absolute value of denominator + return Math.abs(numerator) < Math.abs(denominator); +} // 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. @@ -43,6 +39,4 @@ function assertEquals(actualOutput, targetOutput) { assertEquals(isProperFraction(1, 2), true); assertEquals(isProperFraction(2, 1), false); assertEquals(isProperFraction(-1, -2), true); -assertEquals(isProperFraction("1", 2), 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 c7559e787e..4a715fea5c 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 @@ -21,10 +21,50 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. +// TODO: Implement this function function getCardValue(card) { - // TODO: Implement this function + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + const validSuits = ["♠", "♥", "♦", "♣"]; + //Validation + // Must be a string + if (typeof card !== "string") { + throw Error("Invalid card"); + } + // Must be at least 2 characters and maximum of 3 + // + // } +// ---------- INVALID CHECKS FIRST ---------- + // 1. Must be a string + + + // 2. Must have at least 2 characters (rank + suit) + if (card.length < 2) { + throw new Error("Invalid card"); + } + + // 3. Extract suit and rank + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + // 4. Suit must be valid + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + + // 5. Rank must be valid + if (!validRanks.includes(rank)) { + throw new Error("Invalid card"); + } + + // ---------- ALL INPUT IS NOW VALID ---------- + + if (rank === "A") return 11; + if (["J", "Q", "K"].includes(rank)) return 10; + + return Number(rank); +} // 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; 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 ed77c6ced9..5d184d8412 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 @@ -19,9 +19,4 @@ test(`should return false when denominator is smaller than the numerator (1)`, ( test(`should return true when both values are valid numbers`, () => { expect(isProperFraction(-1, -2)).toEqual(true); -}); - -test(`should return false when a number is not an integer`, () => { - expect(isProperFraction("1", 2)).toEqual(false); -}); - +}); \ No newline at end of file From 5ad63799b735d2146928ab8a5de934473307e50a Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Sun, 22 Feb 2026 22:04:32 +0000 Subject: [PATCH 5/9] completed 3-get-card-value.js and 3-get-card-value test.js with comments --- .../implement/3-get-card-value.js | 89 +++++++++++++------ .../3-get-card-value.test.js | 41 ++++++++- 2 files changed, 101 insertions(+), 29 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 4a715fea5c..9a69df6663 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,48 +23,55 @@ // TODO: Implement this function function getCardValue(card) { - const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; - const validSuits = ["♠", "♥", "♦", "♣"]; - //Validation - // Must be a string - if (typeof card !== "string") { - throw Error("Invalid card"); + // 1. declare variables in an array to use for validation + const validRanks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + const validSuits = ["♠", "♥", "♦", "♣"]; + //2. Check that input is a string + if (typeof card !== "string") { + throw new Error("Invalid card"); } - // Must be at least 2 characters and maximum of 3 - // - // -} -// ---------- INVALID CHECKS FIRST ---------- - - // 1. Must be a string - - - // 2. Must have at least 2 characters (rank + suit) - if (card.length < 2) { + // 3. Must have at least 2 characters but 3 or less (rank and suit) + if (card.length < 2 || card.length > 3) { throw new Error("Invalid card"); } - // 3. Extract suit and rank + // 4. Defining the suit and rank + //Select character index -1, the last character only. const suit = card.slice(-1); + //select everything from index 0 and stop before the last character const rank = card.slice(0, -1); - // 4. Suit must be valid + // 5. Checking suit validity + //Checks if suit is in the array if (!validSuits.includes(suit)) { throw new Error("Invalid card"); } - - // 5. Rank must be valid + // 6. Checking rank validity + //Checks if rank is in the array if (!validRanks.includes(rank)) { throw new Error("Invalid card"); } - - // ---------- ALL INPUT IS NOW VALID ---------- - + //7. Determines the output values for special cards if (rank === "A") return 11; if (["J", "Q", "K"].includes(rank)) return 10; - + // 8. Otherwise it returns the number of the card return Number(rank); } + // 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; @@ -80,6 +87,10 @@ 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("Q♥"), 10); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("J♣"), 10); // Handling invalid cards try { @@ -87,6 +98,32 @@ try { // 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 (error) {} // What other invalid card cases can you think of? +try { + getCardValue("789"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card"); +} catch (error) {} + +try { + getCardValue(""); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("♠♥♦♣"); + console.error("Error was not thrown for invalid card"); +} catch (error) {} + +try { + getCardValue("5$"); + console.error("Error was not thrown for invalid card"); +} catch (error) {} + +try { + getCardValue("£50"); + console.error("Error was not thrown for invalid card"); +} catch (error) {} 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..7e50ef267e 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 @@ -6,13 +6,48 @@ const getCardValue = require("../implement/3-get-card-value"); // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); -}); - + expect(getCardValue("A♠")).toEqual(11)}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +test(`Should return a number given 9 card` , ()=> { + expect(getCardValue("9♠")).toEqual(9)}); // Face Cards (J, Q, K) +test(`Should return 10 when given a Queen card`, () => { + expect(getCardValue("Q♥")).toEqual(10); +}); +test(`Should return 10 when given a King card`, () => { + expect(getCardValue("K♦")).toEqual(10); +}); + +test(`Should return 10 when given a Jack card`, () => { + expect(getCardValue("J♣")).toEqual(10); +}); + // Invalid Cards +test('Should throw "Invalid card" for "invalid"', () => { + expect(() => getCardValue("invalid")).toThrow("Invalid card"); +}); + +test('Should throw "Invalid card" for input "789"', () => { + expect(() => getCardValue("789")).toThrow("Invalid card"); +}); + +test('Should throw "Invalid card" for input ""', () => { + expect(() => getCardValue("")).toThrow("Invalid card"); +}); + +test('Should throw "Invalid card" for input "♠♥♦♣"', () => { + expect(() => getCardValue("♠♥♦♣")).toThrow("Invalid card"); +}); + +test('Should throw "Invalid card" for input "♠♥♦♣"', () => { + expect(() => getCardValue("5$")).toThrow("Invalid card"); +}); + +test('Should throw "Invalid card" for input "♠♥♦♣"', () => { + expect(() => getCardValue("£50")).toThrow("Invalid card"); +}); + // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 5e44659a3ea73027bee55f50701875806c83f9b1 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Mon, 23 Feb 2026 19:50:34 +0000 Subject: [PATCH 6/9] updated invalid card values in 3-get-card-value-test.js --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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 7e50ef267e..142870b5bb 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 @@ -40,11 +40,11 @@ test('Should throw "Invalid card" for input "♠♥♦♣"', () => { expect(() => getCardValue("♠♥♦♣")).toThrow("Invalid card"); }); -test('Should throw "Invalid card" for input "♠♥♦♣"', () => { +test('Should throw "Invalid card" for input "5$"', () => { expect(() => getCardValue("5$")).toThrow("Invalid card"); }); -test('Should throw "Invalid card" for input "♠♥♦♣"', () => { +test('Should throw "Invalid card" for input "£50"', () => { expect(() => getCardValue("£50")).toThrow("Invalid card"); }); From 8234f45168be6e260241601972476bce4638906e Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Wed, 4 Mar 2026 17:34:41 +0000 Subject: [PATCH 7/9] updated 1-get-angle-type-test.js and get-angle-type.js fixed invalid angle value and formatted code using prettier --- .../implement/1-get-angle-type.js | 34 +++++++++---------- .../1-get-angle-type.test.js | 16 ++++----- 2 files changed, 24 insertions(+), 26 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 7695a3895c..0fd7a0b3ca 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 @@ -14,31 +14,29 @@ // 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 <90){ +function getAngleType(angle) { + if (angle > 0 && angle < 90) { return "Acute angle"; } - if(angle === 90){ + if (angle === 90) { return "Right angle"; } - if(angle >90 && angle <180){ + if (angle > 90 && angle < 180) { return "Obtuse angle"; } - if(angle === 180){ + if (angle === 180) { return "Straight angle"; } - if(angle >180 && angle <360){ + if (angle > 180 && angle < 360) { return "Reflex angle"; } - return "Invalid angle found" + return "Invalid angle"; } - - // TODO: Implement this function - +// TODO: Implement this function // 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. @@ -71,14 +69,14 @@ const reflex = getAngleType(275); assertEquals(reflex, "Reflex angle"); // test invalid cases -const invalidAngleCase1 = getAngleType (0); -assertEquals(invalidAngleCase1, "Invalid angle found"); +const invalidAngleCase1 = getAngleType(0); +assertEquals(invalidAngleCase1, "Invalid angle"); -const invalidAngleCase2 = getAngleType (-15); -assertEquals(invalidAngleCase2, "Invalid angle found"); +const invalidAngleCase2 = getAngleType(-15); +assertEquals(invalidAngleCase2, "Invalid angle"); -const invalidAngleCase3 = getAngleType (360); -assertEquals(invalidAngleCase3, "Invalid angle found"); +const invalidAngleCase3 = getAngleType(360); +assertEquals(invalidAngleCase3, "Invalid angle"); -const invalidAngleCase4 = getAngleType (400); -assertEquals(invalidAngleCase4, "Invalid angle found"); \ No newline at end of file +const invalidAngleCase4 = getAngleType(400); +assertEquals(invalidAngleCase4, "Invalid angle"); 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 7148cb5d05..66248faf3c 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 @@ -9,9 +9,9 @@ const getAngleType = require("../implement/1-get-angle-type"); // Case 1: Acute angles // When angle is greater that 0 and less than 90 test(`should return "Acute angle" when (angle >0 angle < 90)`, () => { - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(1)).toEqual("Acute angle"); + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(89)).toEqual("Acute angle"); }); // Case 2: Right angles @@ -44,9 +44,9 @@ test(`should return "Reflex angle" when (angle >180 & angle <360)`, () => { // Case 6: Invalid angles // When angle is equal to or less than 0 and is equal to or greater than 360 -test(`should return "Invalid angle found" when (angle <= 0 or angle >= 360)`, () => { - expect(getAngleType(0)).toEqual("Invalid angle found"); - expect(getAngleType(-1)).toEqual("Invalid angle found"); - expect(getAngleType(360)).toEqual("Invalid angle found"); - expect(getAngleType(520)).toEqual("Invalid angle found"); +test(`should return "Invalid angle" when (angle <= 0 or angle >= 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(520)).toEqual("Invalid angle"); }); From d83c685f381ea870cb49e7d0cf666f1f62add63d Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Wed, 4 Mar 2026 18:13:07 +0000 Subject: [PATCH 8/9] updated 2-is-proper-function-test.js to make test description clearer also formatted with Prettier --- .../implement/2-is-proper-fraction.js | 18 +++++++++--------- .../2-is-proper-fraction.test.js | 12 ++++++------ 2 files changed, 15 insertions(+), 15 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 bc33e2dda3..ce096314e2 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 @@ -10,14 +10,14 @@ // 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) { +function isProperFraction(numerator, denominator) { // Denominator cannot be 0 because it won't make a fraction. - if (denominator === 0) { - return false; - } - // Compare absolute values to eliminate negative values - //Proper fraction = absolute value of numerator < absolute value of denominator - return Math.abs(numerator) < Math.abs(denominator); + if (denominator === 0) { + return false; + } + // Compare absolute values to eliminate negative values + //Proper fraction = absolute value of numerator < absolute value of denominator + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. @@ -36,7 +36,7 @@ function assertEquals(actualOutput, targetOutput) { // What combinations of numerators and denominators should you test? // Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 0), false); assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(1, 2), true); assertEquals(isProperFraction(-1, -2), true); -assertEquals(isProperFraction(1, 0), false); 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 5d184d8412..16f4ec7f08 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 @@ -9,14 +9,14 @@ test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); -test(`should return true when denominator is greater than numerator (2)`, () => { - expect(isProperFraction(1, 2)).toEqual(true); +test("should return false when absolute numerator is greater than or equal to absolute denominator", () => { + expect(isProperFraction(2, 1)).toEqual(false); }); -test(`should return false when denominator is smaller than the numerator (1)`, () => { - expect(isProperFraction(2, 1)).toEqual(false); +test("should return true when absolute numerator is less than absolute denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); }); -test(`should return true when both values are valid numbers`, () => { +test("should correctly handle negative numbers using absolute values", () => { expect(isProperFraction(-1, -2)).toEqual(true); -}); \ No newline at end of file +}); From 3bba9c30139dadaccd85e961ff0baa1d61f81b70 Mon Sep 17 00:00:00 2001 From: AngelaMcLeary Date: Wed, 4 Mar 2026 20:03:13 +0000 Subject: [PATCH 9/9] updated 3-get-card-value-test.js with grouped testing and loops on some tests also formatted code --- .../3-get-card-value.test.js | 107 +++++++++++++----- 1 file changed, 76 insertions(+), 31 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 142870b5bb..7c02e36b1f 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 @@ -4,52 +4,97 @@ 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)}); +// Case 1: Ace (A) - works +// 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) -test(`Should return a number given 9 card` , ()=> { - expect(getCardValue("9♠")).toEqual(9)}); -// Face Cards (J, Q, K) -test(`Should return 10 when given a Queen card`, () => { - expect(getCardValue("Q♥")).toEqual(10); +// Number Cards (2-10) - works +// test(`Should return a number given (2-10) 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) - works +// test(`Should return 10 when given a Queen, King and Jack cards`, () => { +// expect(getCardValue("Q♥")).toEqual(10); +// expect(getCardValue("K♦")).toEqual(10); +// expect(getCardValue("J♣")).toEqual(10); +// }); + +// Invalid Cards - works +// test('Should throw "Invalid card" for "invalid"', () => { +// expect(() => getCardValue("invalid")).toThrow("Invalid card"); +// expect(() => getCardValue("789")).toThrow("Invalid card"); +// expect(() => getCardValue("")).toThrow("Invalid card"); +// expect(() => getCardValue("♠♥♦♣")).toThrow("Invalid card"); +// expect(() => getCardValue("5$")).toThrow("Invalid card"); +// expect(() => getCardValue("£50")).toThrow("Invalid card"); +// }); + +// **Invalid Cards - this only checks the array of invalid input. I have to think about how to +// use the loop here in the reverse order, what is valid or else return invalid!** +// test('should throw "Invalid card" for invalid inputs', () => { +// const invalidCards = ["invalid", "789", "", "♠♥♦♣", "5$", "£50"]; + +// for (const card of invalidCards) { +// expect(() => getCardValue(card)).toThrow("Invalid card"); +// } +// }); + +// Case 1: Ace (A) +test("should return a value of 11 when given Ace cards", () => { + const validSuits = ["♠", "♥", "♦", "♣"]; + + for (let i = 0; i < validSuits.length; i++) { + const card = "A" + validSuits[i]; + expect(getCardValue(card)).toEqual(11); + } }); -test(`Should return 10 when given a King card`, () => { - expect(getCardValue("K♦")).toEqual(10); + +// Suggestion: Group the remaining test data into these categories: +// Case 2: Number Cards (2-10) +test("should return the value of number cards (2-10)", () => { + const validSuits = ["♠", "♥", "♦", "♣"]; + for (let rank = 2; rank <= 10; rank++) { + for (let suit of validSuits) { + const card = `${rank}${suit}`; + expect(getCardValue(card)).toEqual(rank); + } + } }); -test(`Should return 10 when given a Jack card`, () => { - expect(getCardValue("J♣")).toEqual(10); +// Case 3: Face Cards (J, Q, K) +test("should return a value of 10 for cards (J, Q, K)", () => { + const validRanks = ["J", "Q", "K"]; + const validSuits = ["♠", "♥", "♦", "♣"]; + + for (let rank of validRanks) { + for (let suit of validSuits) { + const card = `${rank}${suit}`; + expect(getCardValue(card)).toEqual(10); + } + } }); -// Invalid Cards +// Case 4: Invalid Cards test('Should throw "Invalid card" for "invalid"', () => { expect(() => getCardValue("invalid")).toThrow("Invalid card"); -}); - -test('Should throw "Invalid card" for input "789"', () => { expect(() => getCardValue("789")).toThrow("Invalid card"); -}); - -test('Should throw "Invalid card" for input ""', () => { expect(() => getCardValue("")).toThrow("Invalid card"); -}); - -test('Should throw "Invalid card" for input "♠♥♦♣"', () => { expect(() => getCardValue("♠♥♦♣")).toThrow("Invalid card"); -}); - -test('Should throw "Invalid card" for input "5$"', () => { expect(() => getCardValue("5$")).toThrow("Invalid card"); -}); - -test('Should throw "Invalid card" for input "£50"', () => { expect(() => getCardValue("£50")).toThrow("Invalid card"); }); - // 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 -