From a768fd5c73a0c224c1efc41f7dcc8eafb705a641 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 26 Jun 2026 17:06:57 +0100 Subject: [PATCH 1/5] For committing in implement-and-rewrite-tests exercises --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 1 + .../implement/2-is-proper-fraction.js | 1 + .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 1 + 3 files changed, 3 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 9e05a871e2..57bd93c9f5 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 @@ -35,3 +35,4 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); +//for committing// \ No newline at end of file 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..154dce8939 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 @@ -31,3 +31,4 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +//for committing// \ No newline at end of file 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..80da516407 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 @@ -52,3 +52,4 @@ try { } // What other invalid card cases can you think of? +//for committing// \ No newline at end of file From 543d643429e33e8c40099049e727827c625e3f88 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Wed, 24 Jun 2026 12:10:38 +0100 Subject: [PATCH 2/5] sprint3/implement task-2 --- .../implement/1-get-angle-type.js | 28 +++++++++++-- .../implement/2-is-proper-fraction.js | 7 +++- Sprint-3/package.json | 42 +++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 Sprint-3/package.json 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 57bd93c9f5..d188414888 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 @@ -1,5 +1,4 @@ // Implement a function getAngleType -// // When given an angle in degrees, it should return a string indicating the type of angle: // - "Acute angle" for angles greater than 0° and less than 90° // - "Right angle" for exactly 90° @@ -15,7 +14,24 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + else if(angle === 90){ + return "Right angle"; + } + else if(angle >90 && angle < 180){ + return "Obtuse angle"; + } + else if(angle === 180){ + return "Straight angle"; + } + else if(angle >180 && angle<360){ + return "Reflex angle"; + } + else if(angle>0 && angle < 90){ + return "Acute angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -31,8 +47,14 @@ function assertEquals(actualOutput, targetOutput) { ); } + + // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); +<<<<<<< HEAD assertEquals(right, "Right angle"); -//for committing// \ No newline at end of file +//for committing// +======= +assertEquals(getAngleType(90), "Right angle"); +>>>>>>> 5ef4721 (sprint3/implement task-2) 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 154dce8939..edb1529a47 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,12 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + + return numerator< denominator ; + + + + } // The line below allows us to load the isProperFraction function into tests in other files. diff --git a/Sprint-3/package.json b/Sprint-3/package.json new file mode 100644 index 0000000000..90405bdf0d --- /dev/null +++ b/Sprint-3/package.json @@ -0,0 +1,42 @@ +{ + "name": "week-4-test-example", + "description": "An example application showing how to write tests using the jest framework", + "scripts": { + "test": "jest" + }, + "devDependencies": { + "jest": "^29.5.0" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From eb0fff6fbbcc86cdef69e96dd08b2ef5b6dec529 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 2 Jul 2026 16:50:39 +0100 Subject: [PATCH 3/5] implement rewrite tests/ get-angle-type --- .../implement/1-get-angle-type.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index d188414888..d37f305526 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 @@ -52,9 +52,4 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); -<<<<<<< HEAD -assertEquals(right, "Right angle"); -//for committing// -======= assertEquals(getAngleType(90), "Right angle"); ->>>>>>> 5ef4721 (sprint3/implement task-2) From dae666b75efb8f23b7b8c95bfc9d495822dd173d Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 2 Jul 2026 16:51:38 +0100 Subject: [PATCH 4/5] proper-fraction --- .../implement/2-is-proper-fraction.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index edb1529a47..1cd5ed1e28 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 @@ -14,9 +14,6 @@ function isProperFraction(numerator, denominator) { return numerator< denominator ; - - - } // The line below allows us to load the isProperFraction function into tests in other files. @@ -36,4 +33,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); -//for committing// \ No newline at end of file +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(2, 2), false); + + +assertEquals(isProperFraction(0, 2), true); From 212966dd2197693094301dc1c7a901f8429dfc13 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 2 Jul 2026 16:52:52 +0100 Subject: [PATCH 5/5] get-card-value --- .../implement/3-get-card-value.js | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 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 80da516407..77877564af 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 @@ -1,6 +1,4 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - -// Implement a function getCardValue, when given a string representing a playing card, +/// Implement a function getCardValue, when given a string representing a playing card, // should return the numerical value of the card. // A valid card string will contain a rank followed by the suit. @@ -22,9 +20,25 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + const rank = card.slice(0, -1); + + + + if (rank === "A"){ + return 11 ; + } + else if (rank === "J" || rank === "Q" || rank === "K"){ + return 10 ; + }; + +const value = Number(rank); + + if( value>=2 && value <= 10 ){ + return value}; + + throw new Error("invalid card!"); +} // 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; @@ -39,7 +53,7 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: -assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("9♥"), 9); // Handling invalid cards try { @@ -50,6 +64,22 @@ try { } catch (e) { console.log("Error thrown for invalid card 🎉"); } + +try { + getCardValue("null"); + + console.error("Error was not thrown for null card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉") +} + +try { + getCardValue("0"); + + console.error("Error was not thrown for 0 card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉") +} // What other invalid card cases can you think of? -//for committing// \ No newline at end of file +