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..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 @@ -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,7 +47,9 @@ function assertEquals(actualOutput, targetOutput) { ); } + + // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); -assertEquals(right, "Right angle"); +assertEquals(getAngleType(90), "Right angle"); 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..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 @@ -11,7 +11,9 @@ // 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. @@ -31,3 +33,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(2, 2), false); + + +assertEquals(isProperFraction(0, 2), true); 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..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,5 +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? + 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" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +