From 4b42eded341f4629de4bda1518d0afd533845ba9 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 22 Feb 2026 16:29:44 +0000 Subject: [PATCH] i've now learned how to move files from 1 branch to another : | --- .../implement/1-get-angle-type.js | 25 ++++++++- .../implement/2-is-proper-fraction.js | 11 +++- .../implement/3-get-card-value.js | 51 ++++++++++++------- .../1-get-angle-type.test.js | 25 ++++++++- .../2-is-proper-fraction.test.js | 15 ++++++ .../3-get-card-value.test.js | 26 +++++++++- 6 files changed, 128 insertions(+), 25 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 9e05a871e..da091673d 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,9 +15,30 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 360) + angleType = "Invalid" + else if (angle > 180){ + angleType = "Reflex angle" + } + else if (angle == 180){ + angleType = "Straight angle" + } + else if (angle > 90){ + angleType = "Obtuse angle" + } + else if ( angle == 90){ + angleType = "Right angle" + } + else { + angleType = "Acute angle" + } + + return angleType } +console.log(getAngleType(320)); + + // 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; @@ -30,7 +51,7 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } - +assertEquals(getAngleType(320), "Acute angle"); // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b64..718f718a6 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 (numerator >= denominator) { + return false; + } else { + return true; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(5, 6), true); +assertEquals(isProperFraction(1, 100), true); +assertEquals(isProperFraction(3, 2), false); +assertEquals(isProperFraction(9, 9), false); +assertEquals(isProperFraction(100, 2), 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 c7559e787..ca9699157 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,7 +22,33 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const cardSuit = card.slice(card.length - 1); + const cardRank = card.slice(0, card.length - 1); + let cardValue; + if ( + ["♠", "♥", "♦", "♣"].includes(cardSuit) && + ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"].includes( + cardRank + ) + ) { + if (cardRank == "1") { + throw "invalid"; + } + + switch (cardRank) { + case "A": + return 11; + case "K": + case "Q": + case "J": + return 10; + //case "1": throw RangeError("invalid") + default: + return parseInt(cardRank); + } + } else { + throw "invalid"; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -30,23 +56,10 @@ function getCardValue(card) { 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}` - ); -} +// function assertEquals(actualOutput, targetOutput) { +// console.assert( +// actualOutput === targetOutput, +// `Expected ${actualOutput} to equal ${targetOutput}` // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -// What other invalid card cases can you think of? +//invalid card cases can you think of? diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d..55b22885c 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 @@ -13,8 +13,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(89)).toEqual("Acute angle"); }); -// Case 2: Right angle +//Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90> angle < 180)`,() =>{ + expect(getAngleType(91)).toEqual("Obtuse angle") + expect(getAngleType(127)).toEqual("Obtuse angle") + expect(getAngleType(179)).toEqual("Obtuse 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 "Reflex angle" when (180> angle <=360)`,()=>{ + expect(getAngleType(181)).toEqual("Reflex angle") + expect(getAngleType(270)).toEqual("Reflex angle") + expect(getAngleType(359)).toEqual("Reflex angle") + + }); // Case 6: Invalid angles + test(`should return "Invalid angle" when(360>)`,()=>{ + expect(getAngleType(361)).toEqual("Invalid") + }); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba..d0148e1f9 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 @@ -7,4 +7,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(0,0)).toEqual(false) +}); + +// Where the numerator is > than the denominator +test(`should return false when the (numerator > denominator)`,()=>{ + expect(isProperFraction(4,2)).toEqual(false) + expect(isProperFraction(100,6)).toEqual(false) + expect(isProperFraction(5,-10)).toEqual(false) +}); + +// Where the fraction is correct +test(`Should return a true when the (numerator < denominator)`,()=>{ + expect(isProperFraction(1,2)).toEqual(true) + expect(isProperFraction(6,8)).toEqual(true) + expect(isProperFraction(-1,2)).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 cf7f9dae2..639ffa09e 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 @@ -7,14 +7,36 @@ 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); + 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 11 when given an ace card`, () => { + expect(getCardValue("7♠")).toEqual(7); + expect(getCardValue("9♣")).toEqual(9); + expect(getCardValue("3♥")).toEqual(3); + expect(getCardValue("5♦")).toEqual(5); +}); // Face Cards (J, Q, K) -// Invalid Cards +test(`Should return 11 when given an ace card`, () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); + //Invalid Cards +test("throws on invalid card", () => { + expect(() => { + getCardValue("JJ"); }).toThrow("invalid"); + expect(() => { + getCardValue("1♠"); }).toThrow("invalid"); +expect(() => { + getCardValue("A1"); }).toThrow("invalid"); +}); // 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 -