From 4ea74f505b84ae78a1d7e2e3d8985c048048d778 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Wed, 8 Jul 2026 19:46:11 +0100 Subject: [PATCH 01/20] function and assertion tests completed --- .../implement/1-get-angle-type.js | 29 ++++++++++++++++++- 1 file changed, 28 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..c6f90d208c 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,18 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const invalid = getAngleType(0); +assertEquals(invalid, "Invalid angle"); + +const acute = getAngleType(89); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(91); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle") + +const invalid1 = getAngleType(360); +assertEquals(invalid1, "Invalid angle") \ No newline at end of file From ecd12aa869395168eef5d650843f7a0bf3d855ea Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Wed, 8 Jul 2026 19:55:44 +0100 Subject: [PATCH 02/20] reformatted --- .../implement/1-get-angle-type.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 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 c6f90d208c..ea542bf2ff 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,19 +15,19 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - 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" - } + 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. @@ -37,10 +37,10 @@ module.exports = getAngleType; // This helper function is written to make our assertions easier to read. // If the actual output matches the target output, the test will pass function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } // TODO: Write tests to cover all cases, including boundary and invalid cases. From a4ba8bc5f2ac9f58fdbddb3f476c374174bb1a1c Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Wed, 8 Jul 2026 20:04:01 +0100 Subject: [PATCH 03/20] added more test cases to cover all boundaries --- .../implement/1-get-angle-type.js | 20 ++++++++++++++++++- 1 file changed, 19 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 ea542bf2ff..a15aa98125 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 @@ -61,4 +61,22 @@ const straight = getAngleType(180); assertEquals(straight, "Straight angle") const invalid1 = getAngleType(360); -assertEquals(invalid1, "Invalid angle") \ No newline at end of file +assertEquals(invalid1, "Invalid angle") + +const acute1 = getAngleType(1); +assertEquals(acute1, "Acute angle") + +const obtuse1 = getAngleType(179); +assertEquals(obtuse1, "Obtuse angle") + +const reflex = getAngleType(181); +assertEquals(reflex, "Reflex angle") + +const reflex1 = getAngleType(359); +assertEquals(reflex1, "Reflex angle") + +const invalid2 = getAngleType(-1); +assertEquals(invalid2, "Invalid angle") + +const invalid3 = getAngleType(361); +assertEquals(invalid3, "Invalid angle") \ No newline at end of file From 822fcbcc2a38226dd7e1d4387ae71d2f70ec9f6d Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Wed, 8 Jul 2026 20:46:30 +0100 Subject: [PATCH 04/20] implemented the function and added test cases to cover all boundaries --- .../implement/2-is-proper-fraction.js | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 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..afbb588f4b 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,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (Number.isFinite(numerator) && Number.isFinite(denominator)) { + if(numerator < denominator){ + return true + } + } return false } // The line below allows us to load the isProperFraction function into tests in other files. @@ -20,10 +24,10 @@ module.exports = isProperFraction; // Here's our helper again function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } // TODO: Write tests to cover all cases. @@ -31,3 +35,26 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(5, 5), false); +assertEquals(isProperFraction(0, 5), true); +assertEquals(isProperFraction(5, 0), false); +assertEquals(isProperFraction(0, 0), false); +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), false); +assertEquals(isProperFraction(-2, -1), true); +assertEquals(isProperFraction(-1, -2), false); +assertEquals(isProperFraction(0.5, 1), true); +assertEquals(isProperFraction(1.5, 1), false); +assertEquals(isProperFraction(Infinity, 2), false); +assertEquals(isProperFraction(2, Infinity), false); +assertEquals(isProperFraction(NaN, 2), false); +assertEquals(isProperFraction(2, NaN), false); +assertEquals(isProperFraction(999999999, 1000000000), true); + + + + + + + From 1a96b7dbd5b616532e3989a288d3fa8c89a1ab8b Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 16 Jul 2026 20:34:04 +0100 Subject: [PATCH 05/20] completed and tested card game --- .../implement/3-get-card-value.js | 79 +++++++++++++++++-- 1 file changed, 74 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 ff5c532e1d..f2edf84d6c 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,9 +22,37 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const rank = card.slice(0, card.length -1).toUpperCase() + const suit = card.slice(card.length -1) + + const suits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + + // Basic validation + if(card === ""){ + throw new Error("No card was played") + } + if(card.length < 2 || card.length > 3 ){ + throw new Error("Invalid card played, rank and suit cannot be less than 1 or more than 3") + } + // Suit validation + if(!suits.includes(suit)){ + throw new Error("Invalid card played, suit is missing"); + } + // Rank validation + if(!validRanks.includes(rank)){ + throw new Error("Invalid rank played") + } + if(rank === "A"){ + return 11 + }else if(rank === "J" || rank === "Q" || rank === "K"){ + return 10 + }else{ + 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; @@ -37,18 +65,59 @@ 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("A♥"), 11); +assertEquals(getCardValue("A♦"), 11); +assertEquals(getCardValue("A♣"), 11); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("3♥"), 3); +assertEquals(getCardValue("4♦"), 4); +assertEquals(getCardValue("5♣"), 5); +assertEquals(getCardValue("6♠"), 6); +assertEquals(getCardValue("7♥"), 7); +assertEquals(getCardValue("8♦"), 8); +assertEquals(getCardValue("9♣"), 9); +assertEquals(getCardValue("10♠"), 10); +assertEquals(getCardValue("J♠"), 10); +assertEquals(getCardValue("Q♥"), 10); +assertEquals(getCardValue("K♦"), 10); // Handling invalid cards try { - getCardValue("invalid"); + getCardValue(""); // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card 😢"); } catch (e) { - console.log("Error thrown for invalid card 🎉"); + console.log(e); } // What other invalid card cases can you think of? +try{ + getCardValue("100"); + console.error("Error was not thrown for card with more than 3 in length"); +} catch (e){ + console.log(e) +} +try{ + getCardValue("1") + console.error("Error was not thrown for a card.lenght = 1") +}catch (e){ + console.log(e) +} + +try{ + getCardValue("♦") + console.error("Error was not thrown for a card play of just suits") +}catch (e){ + console.log(e) +} + +try{ + getCardValue("A😊") + console.error("Error was not thrown for a card play of a wrong suit") +}catch (e){ + console.log(e) +} + From c727523a25f407526af488f774215702ae2dd88d Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Fri, 17 Jul 2026 19:53:02 +0100 Subject: [PATCH 06/20] adding additional test --- .../implement/3-get-card-value.js | 3 ++- 1 file changed, 2 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 f2edf84d6c..944611664d 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 @@ -93,7 +93,7 @@ try { console.log(e); } -// What other invalid card cases can you think of? +// What other invalid card cases can you think of? try{ getCardValue("100"); console.error("Error was not thrown for card with more than 3 in length"); @@ -121,3 +121,4 @@ try{ console.log(e) } + From 62aab55b7b9f742028b80ba86a8660ff88701528 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 19 Jul 2026 14:45:32 +0100 Subject: [PATCH 07/20] all jest tests pass in 1-angle-type.js --- .../implement/1-get-angle-type.js | 10 +++---- .../1-get-angle-type.test.js | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 9 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 a15aa98125..1f3383ff62 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 @@ -17,13 +17,13 @@ function getAngleType(angle) { if (angle > 0 && angle < 90) { return "Acute angle" - } else if (angle === 90) { + } if (angle === 90) { return "Right angle" - } else if (angle > 90 && angle < 180) { + } if (angle > 90 && angle < 180) { return "Obtuse angle" - } else if (angle === 180) { + } if (angle === 180) { return "Straight angle" - } else if (angle > 180 && angle < 360) { + } if (angle > 180 && angle < 360) { return "Reflex angle" } else { return "Invalid angle" @@ -78,5 +78,3 @@ assertEquals(reflex1, "Reflex angle") const invalid2 = getAngleType(-1); assertEquals(invalid2, "Invalid angle") -const invalid3 = getAngleType(361); -assertEquals(invalid3, "Invalid angle") \ 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..4e6978d729 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,6 @@ // 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, // including boundary and invalid cases. // Case 1: Acute angles @@ -13,8 +12,30 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(89)).toEqual("Acute angle"); }); -// Case 2: Right angle -// Case 3: Obtuse angles + +// Case 2: Obtuse angle +test(`should return "obtuse angle" when (90 < angle < 180 `, () =>{ + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); + +}) +// Case 3: Right angles +test(`should return "Right angle" when (angle === 90)`, () => { + expect(getAngleType(90)).toEqual("Right 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 "Reflect angle" when (180 < angle < 360))`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}) // Case 6: Invalid angles +test(`should return "Invalid angle" when (0 > angle > 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-1)).toEqual("Invalid angle"); +}) From 09fe227d8b7431b1dd4b54e583845fed63595b9c Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 19 Jul 2026 15:23:54 +0100 Subject: [PATCH 08/20] all jest tests pass in 2-is-proper-fraction.js --- .../2-is-proper-fraction.test.js | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 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 7f087b2ba1..7fb0cd4c9f 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,32 @@ // 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. // Special case: numerator is zero test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(1,2 )).toEqual(true); + expect(isProperFraction(2,1)).toEqual(false); + expect(isProperFraction(5,5)).toEqual(false); + expect(isProperFraction(0,5)).toEqual(true); + expect(isProperFraction(5,0)).toEqual(false); + expect(isProperFraction(0,0)).toEqual(false); + expect(isProperFraction(-1,2)).toEqual(true); + expect(isProperFraction(1,-2)).toEqual(false); + expect(isProperFraction(-2,-1)).toEqual(true); + expect(isProperFraction(-1,-2)).toEqual(false); + expect(isProperFraction(0.5,1)).toEqual(true); + expect(isProperFraction(1.5,1)).toEqual(false); + expect(isProperFraction(Infinity,2)).toEqual(false); + expect(isProperFraction(2,Infinity)).toEqual(false); + expect(isProperFraction(NaN,2)).toEqual(false) + expect(isProperFraction(2,NaN)).toEqual(false); + expect(isProperFraction(999999999, 1000000000)).toEqual(true) + + + + + + + + }); From 8270fd63f275ff3034e62af8a70cf5ef3632ecc5 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 19 Jul 2026 16:38:41 +0100 Subject: [PATCH 09/20] refactored --- .../implement/3-get-card-value.js | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 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 944611664d..94b781830f 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,34 +22,35 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - const rank = card.slice(0, card.length -1).toUpperCase() - const suit = card.slice(card.length -1) - - const suits = ["♠", "♥", "♦", "♣"]; - const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; - - // Basic validation - if(card === ""){ + // Basic validation: validating the input before slicing + if (card === "") { throw new Error("No card was played") } - if(card.length < 2 || card.length > 3 ){ + if (card.length < 2 || card.length > 3) { throw new Error("Invalid card played, rank and suit cannot be less than 1 or more than 3") } - // Suit validation - if(!suits.includes(suit)){ + const rank = card.slice(0, card.length - 1).toUpperCase() + const suit = card.slice(card.length - 1) + + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + + // Suit and rank validation + if (!validSuits.includes(suit)) { throw new Error("Invalid card played, suit is missing"); } - // Rank validation - if(!validRanks.includes(rank)){ - throw new Error("Invalid rank played") - } - if(rank === "A"){ - return 11 - }else if(rank === "J" || rank === "Q" || rank === "K"){ - return 10 - }else{ - return Number(rank) + if (validRanks.includes(rank)) { + if (rank === "A") { + return 11; + } else if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } else { + return Number(rank); + } + } else { + throw new Error("Invalid rank"); } + } @@ -59,10 +60,10 @@ module.exports = getCardValue; // Helper functions to make our assertions easier to read. function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } // Examples: @@ -85,39 +86,39 @@ assertEquals(getCardValue("K♦"), 10); // Handling invalid cards try { - getCardValue(""); + getCardValue(""); - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid 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) { - console.log(e); + console.log(e); } // What other invalid card cases can you think of? -try{ +try { getCardValue("100"); console.error("Error was not thrown for card with more than 3 in length"); -} catch (e){ +} catch (e) { console.log(e) } -try{ +try { getCardValue("1") console.error("Error was not thrown for a card.lenght = 1") -}catch (e){ +} catch (e) { console.log(e) } -try{ +try { getCardValue("♦") console.error("Error was not thrown for a card play of just suits") -}catch (e){ +} catch (e) { console.log(e) } -try{ +try { getCardValue("A😊") console.error("Error was not thrown for a card play of a wrong suit") -}catch (e){ +} catch (e) { console.log(e) } From f09266784e24ed196a4e439e524c66087d97469a Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 19 Jul 2026 17:11:50 +0100 Subject: [PATCH 10/20] completed jest testing on card game and proper fractions --- .../implement/2-is-proper-fraction.js | 1 - .../2-is-proper-fraction.test.js | 58 ++++++++++--------- .../3-get-card-value.test.js | 29 +++++++++- 3 files changed, 58 insertions(+), 30 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 afbb588f4b..9084237fa4 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 @@ -30,7 +30,6 @@ 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 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 7fb0cd4c9f..49b2e58352 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 @@ -3,31 +3,35 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1,2 )).toEqual(true); - expect(isProperFraction(2,1)).toEqual(false); - expect(isProperFraction(5,5)).toEqual(false); - expect(isProperFraction(0,5)).toEqual(true); - expect(isProperFraction(5,0)).toEqual(false); - expect(isProperFraction(0,0)).toEqual(false); - expect(isProperFraction(-1,2)).toEqual(true); - expect(isProperFraction(1,-2)).toEqual(false); - expect(isProperFraction(-2,-1)).toEqual(true); - expect(isProperFraction(-1,-2)).toEqual(false); - expect(isProperFraction(0.5,1)).toEqual(true); - expect(isProperFraction(1.5,1)).toEqual(false); - expect(isProperFraction(Infinity,2)).toEqual(false); - expect(isProperFraction(2,Infinity)).toEqual(false); - expect(isProperFraction(NaN,2)).toEqual(false) - expect(isProperFraction(2,NaN)).toEqual(false); - expect(isProperFraction(999999999, 1000000000)).toEqual(true) - - - - - - - - +test("should correctly identify proper fractions", () => { + // Whole number fractions + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(5, 5)).toEqual(false); + + // Zero + expect(isProperFraction(0, 5)).toEqual(true); + expect(isProperFraction(5, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); + + // Negative numbers + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(false); + expect(isProperFraction(-2, -1)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(false); + + // Decimal numbers + expect(isProperFraction(0.5, 1)).toEqual(true); + expect(isProperFraction(1.5, 1)).toEqual(false); + + // Infinity + expect(isProperFraction(Infinity, 2)).toEqual(false); + expect(isProperFraction(2, Infinity)).toEqual(false); + + // NaN + expect(isProperFraction(NaN, 2)).toEqual(false); + expect(isProperFraction(2, NaN)).toEqual(false); + + // Large numbers + expect(isProperFraction(999999999, 1000000000)).toEqual(true); }); 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..2ab7e47d80 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,17 +2,42 @@ // 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. // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: +// Suggestion: Group the remaining test data into these categories: // ♠ ♥ ♦ ♣ // Number Cards (2-10) +test(`Should return the card's numeric rank for cards 2 through 10`, () =>{ + 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 the card is a face card ("J", "Q", "K")`, () => { + expect(getCardValue("j♠")).toEqual(10); + expect(getCardValue("k♦")).toEqual(10); + expect(getCardValue("q♣")).toEqual(10); + +}) // Invalid Cards +test("should throw an error when an invalid card is played", () => { + expect(() => getCardValue("")).toThrow("No card was played"); + expect(() => getCardValue("1009♣")).toThrow("Invalid card played, rank and suit cannot be less " + + "than 1 or more than 3") + +}); + + // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 4e5fb74bc555ff63f5812fb344a1d4c52d3c9773 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 10:21:07 +0100 Subject: [PATCH 11/20] is proper fraction has been reimplemented to correctly --- .../implement/2-is-proper-fraction.js | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 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 9084237fa4..6f39a23f8c 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,11 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if (Number.isFinite(numerator) && Number.isFinite(denominator)) { - if(numerator < denominator){ - return true - } - } return false + return denominator !== 0 && Math.abs(numerator / denominator) < 1; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -24,10 +20,10 @@ module.exports = isProperFraction; // Here's our helper again function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } // What combinations of numerators and denominators should you test? @@ -40,20 +36,9 @@ assertEquals(isProperFraction(0, 5), true); assertEquals(isProperFraction(5, 0), false); assertEquals(isProperFraction(0, 0), false); assertEquals(isProperFraction(-1, 2), true); -assertEquals(isProperFraction(1, -2), false); -assertEquals(isProperFraction(-2, -1), true); -assertEquals(isProperFraction(-1, -2), false); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-2, -1), false); +assertEquals(isProperFraction(-1, -2), true); assertEquals(isProperFraction(0.5, 1), true); assertEquals(isProperFraction(1.5, 1), false); -assertEquals(isProperFraction(Infinity, 2), false); -assertEquals(isProperFraction(2, Infinity), false); -assertEquals(isProperFraction(NaN, 2), false); -assertEquals(isProperFraction(2, NaN), false); assertEquals(isProperFraction(999999999, 1000000000), true); - - - - - - - From 95828f580dfd3642ec021790153fb3fc85138764 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 10:37:25 +0100 Subject: [PATCH 12/20] simplified the use of .slice --- .../implement/3-get-card-value.js | 112 ++++++++++-------- 1 file changed, 62 insertions(+), 50 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 94b781830f..6bf0ed0554 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,48 +22,62 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // Basic validation: validating the input before slicing - if (card === "") { - throw new Error("No card was played") - } - if (card.length < 2 || card.length > 3) { - throw new Error("Invalid card played, rank and suit cannot be less than 1 or more than 3") - } - const rank = card.slice(0, card.length - 1).toUpperCase() - const suit = card.slice(card.length - 1) - - const validSuits = ["♠", "♥", "♦", "♣"]; - const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; - - // Suit and rank validation - if (!validSuits.includes(suit)) { - throw new Error("Invalid card played, suit is missing"); - } - if (validRanks.includes(rank)) { - if (rank === "A") { - return 11; - } else if (rank === "J" || rank === "Q" || rank === "K") { - return 10; - } else { - return Number(rank); - } + // Basic validation: validating the input before slicing + if (card === "") { + throw new Error("No card was played"); + } + if (card.length < 2 || card.length > 3) { + throw new Error( + "Invalid card played, rank and suit cannot be less than 1 or more than 3" + ); + } + const rank = card.slice(0, -1).toUpperCase(); + const suit = card.slice(-1); + + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + + // Suit and rank validation + if (!validSuits.includes(suit)) { + throw new Error("Invalid card played, suit is missing"); + } + if (validRanks.includes(rank)) { + if (rank === "A") { + return 11; + } else if (rank === "J" || rank === "Q" || rank === "K") { + return 10; } else { - throw new Error("Invalid rank"); + return Number(rank); } - + } else { + throw new Error("Invalid 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; // Helper functions to make our assertions easier to read. function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); } // Examples: @@ -86,40 +100,38 @@ assertEquals(getCardValue("K♦"), 10); // Handling invalid cards try { - getCardValue(""); + getCardValue(""); - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid 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) { - console.log(e); + console.log(e); } // What other invalid card cases can you think of? try { - getCardValue("100"); - console.error("Error was not thrown for card with more than 3 in length"); + getCardValue("100"); + console.error("Error was not thrown for card with more than 3 in length"); } catch (e) { - console.log(e) + console.log(e); } try { - getCardValue("1") - console.error("Error was not thrown for a card.lenght = 1") + getCardValue("1"); + console.error("Error was not thrown for a card.lenght = 1"); } catch (e) { - console.log(e) + console.log(e); } try { - getCardValue("♦") - console.error("Error was not thrown for a card play of just suits") + getCardValue("♦"); + console.error("Error was not thrown for a card play of just suits"); } catch (e) { - console.log(e) + console.log(e); } try { - getCardValue("A😊") - console.error("Error was not thrown for a card play of a wrong suit") + getCardValue("A😊"); + console.error("Error was not thrown for a card play of a wrong suit"); } catch (e) { - console.log(e) + console.log(e); } - - From a8c0c3b1fb1d0be9c84fc3407ba0192ceaf19181 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 10:40:57 +0100 Subject: [PATCH 13/20] changed error message for invalid suit --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 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 6bf0ed0554..d3d1133c65 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 @@ -53,7 +53,7 @@ function getCardValue(card) { // Suit and rank validation if (!validSuits.includes(suit)) { - throw new Error("Invalid card played, suit is missing"); + throw new Error("Invalid card: suit is not recognised"); } if (validRanks.includes(rank)) { if (rank === "A") { From 4eb7cd76484759f49607e26d48995f19eff6333a Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 10:54:03 +0100 Subject: [PATCH 14/20] refactored: removed redundant code --- .../implement/3-get-card-value.js | 6 +----- 1 file changed, 1 insertion(+), 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 d3d1133c65..73e888495e 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 @@ -26,11 +26,7 @@ function getCardValue(card) { if (card === "") { throw new Error("No card was played"); } - if (card.length < 2 || card.length > 3) { - throw new Error( - "Invalid card played, rank and suit cannot be less than 1 or more than 3" - ); - } + const rank = card.slice(0, -1).toUpperCase(); const suit = card.slice(-1); From 48814ec0e90e8b20ddb08190b77ca7882dc67a4a Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 11:06:48 +0100 Subject: [PATCH 15/20] changed test describtion to be more clear --- .../1-get-angle-type.test.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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 4e6978d729..d3dd08b733 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,37 +5,35 @@ const getAngleType = require("../implement/1-get-angle-type"); // including boundary and invalid cases. // Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { +test(`should return "Invalid angle" when angle is less than 0 or greater than 360')`, () => { // Test various acute angles, including boundary cases expect(getAngleType(1)).toEqual("Acute angle"); expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); - // Case 2: Obtuse angle -test(`should return "obtuse angle" when (90 < angle < 180 `, () =>{ +test(`should return "obtuse angle" when (90 < angle < 180 `, () => { expect(getAngleType(91)).toEqual("Obtuse angle"); expect(getAngleType(179)).toEqual("Obtuse angle"); - -}) +}); // Case 3: Right angles test(`should return "Right angle" when (angle === 90)`, () => { expect(getAngleType(90)).toEqual("Right angle"); -}) +}); // 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 "Reflect angle" when (180 < angle < 360))`, () => { expect(getAngleType(181)).toEqual("Reflex angle"); expect(getAngleType(359)).toEqual("Reflex angle"); -}) +}); // Case 6: Invalid angles test(`should return "Invalid angle" when (0 > angle > 360)`, () => { expect(getAngleType(0)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); expect(getAngleType(-1)).toEqual("Invalid angle"); -}) +}); From c4f94e60b607f6b592e4d43848eeec9aeac3ea92 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Thu, 30 Jul 2026 11:48:52 +0100 Subject: [PATCH 16/20] reimplemented the tests for the function change in proper fraction. --- .../2-is-proper-fraction.test.js | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 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 49b2e58352..edadbd0cda 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,36 +2,51 @@ // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); +// Proper fraction +test("should return true when the denominator is greater than the numerator", () => { + expect(isProperFraction(1, 2)).toBe(true); +}); + +// Improper fraction +test("should return false when the numerator is greater than the denominator", () => { + expect(isProperFraction(2, 1)).toBe(false); +}); + +// Zero numerator +test("should return true when the numerator is zero", () => { + expect(isProperFraction(0, 5)).toBe(true); +}); + +// Zero denominator +test("should return false when the denominator is zero", () => { + expect(isProperFraction(5, 0)).toBe(false); +}); + +// numerator equals denominator +test("should return false when numerator equals denominator ", () => { + expect(isProperFraction(5, 5)).toBe(false); +}); + +// Both numerator and denominator are zero +test("should return false when both the numerator and denominator are zero", () => { + expect(isProperFraction(0, 0)).toBe(false); +}); + +// Negative numbers +test("should correctly identify proper fractions when given negative numbers", () => { + expect(isProperFraction(-1, 2)).toBe(true); + expect(isProperFraction(1, -2)).toBe(true); + expect(isProperFraction(-1, -2)).toBe(true); + expect(isProperFraction(-2, -1)).toBe(false); +}); + +// Decimal numbers +test("should correctly identify proper fractions when given decimal numbers", () => { + expect(isProperFraction(0.5, 1)).toBe(true); + expect(isProperFraction(1.5, 1)).toBe(false); +}); -test("should correctly identify proper fractions", () => { - // Whole number fractions - expect(isProperFraction(1, 2)).toEqual(true); - expect(isProperFraction(2, 1)).toEqual(false); - expect(isProperFraction(5, 5)).toEqual(false); - - // Zero - expect(isProperFraction(0, 5)).toEqual(true); - expect(isProperFraction(5, 0)).toEqual(false); - expect(isProperFraction(0, 0)).toEqual(false); - - // Negative numbers - expect(isProperFraction(-1, 2)).toEqual(true); - expect(isProperFraction(1, -2)).toEqual(false); - expect(isProperFraction(-2, -1)).toEqual(true); - expect(isProperFraction(-1, -2)).toEqual(false); - - // Decimal numbers - expect(isProperFraction(0.5, 1)).toEqual(true); - expect(isProperFraction(1.5, 1)).toEqual(false); - - // Infinity - expect(isProperFraction(Infinity, 2)).toEqual(false); - expect(isProperFraction(2, Infinity)).toEqual(false); - - // NaN - expect(isProperFraction(NaN, 2)).toEqual(false); - expect(isProperFraction(2, NaN)).toEqual(false); - - // Large numbers - expect(isProperFraction(999999999, 1000000000)).toEqual(true); +// Large numbers +test("should correctly identify proper fractions when given very large numbers", () => { + expect(isProperFraction(999999999, 1000000000)).toBe(true); }); From d59acfedb1b1357bc7ba999b868b1a112861ca25 Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sat, 1 Aug 2026 23:13:30 +0100 Subject: [PATCH 17/20] changes made to the notation 0 > angle > 360 --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 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 d3dd08b733..c47011f907 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 @@ -32,7 +32,7 @@ test(`should return "Reflect angle" when (180 < angle < 360))`, () => { expect(getAngleType(359)).toEqual("Reflex angle"); }); // Case 6: Invalid angles -test(`should return "Invalid angle" when (0 > angle > 360)`, () => { +test(`should return "Invalid angle" when angle is less than zero or angle is greater than 360)`, () => { expect(getAngleType(0)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); expect(getAngleType(-1)).toEqual("Invalid angle"); From 70ebf359949abc62dd87cbce031e595ebd31e17f Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sat, 1 Aug 2026 23:20:41 +0100 Subject: [PATCH 18/20] changes made to angle test --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 c47011f907..e1c96eb250 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,18 +2,15 @@ // We will use the same function, but write tests for it using Jest in this file. const getAngleType = require("../implement/1-get-angle-type"); -// including boundary and invalid cases. - // Case 1: Acute angles -test(`should return "Invalid angle" when angle is less than 0 or greater than 360')`, () => { - // Test various acute angles, including boundary cases +test(`should return "Acute angle" when angle is greater than 0 or angle is less than 90')`, () => { expect(getAngleType(1)).toEqual("Acute angle"); expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); // Case 2: Obtuse angle -test(`should return "obtuse angle" when (90 < angle < 180 `, () => { +test(`should return "obtuse angle" when angle is greater than 90 but less than 180 `, () => { expect(getAngleType(91)).toEqual("Obtuse angle"); expect(getAngleType(179)).toEqual("Obtuse angle"); }); @@ -27,7 +24,7 @@ test(`should return "Straight angle" when (angle === 180)`, () => { expect(getAngleType(180)).toEqual("Straight angle"); }); // Case 5: Reflex angles -test(`should return "Reflect angle" when (180 < angle < 360))`, () => { +test(`should return "Reflect angle" when angle is greater than 180 but less than 360))`, () => { expect(getAngleType(181)).toEqual("Reflex angle"); expect(getAngleType(359)).toEqual("Reflex angle"); }); From 0b216f80c865edca61078055e4e7d998ae8bafba Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 2 Aug 2026 00:13:36 +0100 Subject: [PATCH 19/20] changes made to angle test --- .../implement/3-get-card-value.js | 27 +++++++++---------- .../3-get-card-value.test.js | 26 +++++++----------- 2 files changed, 22 insertions(+), 31 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 73e888495e..a81698bc03 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,12 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // Basic validation: validating the input before slicing if (card === "") { throw new Error("No card was played"); } - - const rank = card.slice(0, -1).toUpperCase(); - const suit = card.slice(-1); + if (card.length < 2 || card.length > 3) { + throw new Error("Invalid card"); + } const validSuits = ["♠", "♥", "♦", "♣"]; const validRanks = [ @@ -47,21 +46,19 @@ function getCardValue(card) { "K", ]; - // Suit and rank validation + const suit = card.slice(-1); if (!validSuits.includes(suit)) { throw new Error("Invalid card: suit is not recognised"); } - if (validRanks.includes(rank)) { - if (rank === "A") { - return 11; - } else if (rank === "J" || rank === "Q" || rank === "K") { - return 10; - } else { - return Number(rank); - } - } else { - throw new Error("Invalid rank"); + + const rank = card.slice(0, -1).toUpperCase(); + if (!validRanks.includes(rank)) { + throw new Error("Invalid card: rank is not recognised"); } + 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. 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 2ab7e47d80..de63ffb36a 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,15 +2,13 @@ // We will use the same function, but write tests for it using Jest in this file. const getCardValue = require("../implement/3-get-card-value"); - -// Case 1: Ace (A) +// Ace (A) 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 the card's numeric rank for cards 2 through 10`, () =>{ +test(`Should return the card's numeric rank for cards 2 through 10`, () => { expect(getCardValue("2♠")).toEqual(2); expect(getCardValue("3♥")).toEqual(3); expect(getCardValue("4♦")).toEqual(4); @@ -20,26 +18,22 @@ test(`Should return the card's numeric rank for cards 2 through 10`, () =>{ 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 the card is a face card ("J", "Q", "K")`, () => { expect(getCardValue("j♠")).toEqual(10); expect(getCardValue("k♦")).toEqual(10); expect(getCardValue("q♣")).toEqual(10); +}); -}) // Invalid Cards test("should throw an error when an invalid card is played", () => { expect(() => getCardValue("")).toThrow("No card was played"); - expect(() => getCardValue("1009♣")).toThrow("Invalid card played, rank and suit cannot be less " + - "than 1 or more than 3") - + expect(() => getCardValue("X♠")).toThrow( + "Invalid card: rank is not recognised" + ); + expect(() => getCardValue("9X")).toThrow( + "Invalid card: suit is not recognised" + ); }); - - - -// 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 3e139b57fabdb4547806d202f12be6f63cb788fc Mon Sep 17 00:00:00 2001 From: d-odumosu Date: Sun, 2 Aug 2026 21:40:47 +0100 Subject: [PATCH 20/20] test description changed to match the test --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 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 e1c96eb250..d387b6f103 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 @@ -29,7 +29,7 @@ test(`should return "Reflect angle" when angle is greater than 180 but less than expect(getAngleType(359)).toEqual("Reflex angle"); }); // Case 6: Invalid angles -test(`should return "Invalid angle" when angle is less than zero or angle is greater than 360)`, () => { +test(`"should return 'Invalid angle' when angle is 0, 360, less than 0, or greater than 360")`, () => { expect(getAngleType(0)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); expect(getAngleType(-1)).toEqual("Invalid angle");