From e6eb715bd31ec381388d3f8a58ba77297ae01251 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 16 Feb 2026 16:01:34 +0000 Subject: [PATCH 1/7] angel type done need to do the tests part --- .../implement/1-get-angle-type.js | 23 ++++++++++++++++++- 1 file changed, 22 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 9e05a871e..750fe0c86 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; From 729b6d89d6bd7831a6b15851fa09b3ec73d0dd05 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 17 Feb 2026 15:50:57 +0000 Subject: [PATCH 2/7] first part almost done --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 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 750fe0c86..375e136d1 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 @@ -51,7 +51,7 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } - +console.log(assertEquals((getAngleType(320))), (Reflex)); // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles const right = getAngleType(90); From 990e0cbf3b13d8c0bf72123c0cbc41aeb1d41036 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 17 Feb 2026 16:14:11 +0000 Subject: [PATCH 3/7] made a start --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 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 375e136d1..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 @@ -51,7 +51,7 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } -console.log(assertEquals((getAngleType(320))), (Reflex)); +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); From 478b72b0fffd9911b560a7786fa1234d49b32b2c Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 22 Feb 2026 15:47:04 +0000 Subject: [PATCH 4/7] coursework compleat --- .../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 +++++++++- Sprint-3/2-practice-tdd/count.js | 13 ++++- Sprint-3/2-practice-tdd/count.test.js | 15 ++++-- Sprint-3/2-practice-tdd/get-ordinal-number.js | 17 ++++++- .../2-practice-tdd/get-ordinal-number.test.js | 20 ++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 9 ++-- Sprint-3/2-practice-tdd/repeat-str.test.js | 13 +++-- Sprint-3/3-dead-code/exercise-1.js | 6 --- Sprint-3/3-dead-code/exercise-2.js | 5 -- 13 files changed, 176 insertions(+), 50 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 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 - diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..e8ecfc3e5 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,14 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 +totalCount=stringOfCharacters.split(""); +Count=0 +for(i=0; i { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); + expect(countChar("aaaaa","a")).toEqual(5); }); // Scenario: No Occurrences +test(`should return 0 in the instance of no char counted`,() =>{ + expect(countChar("","a")).toEqual(0); +}); + +//}); // Given the input string `str`, -// And a character `char` that does not exist within `str`. +test(` character char that does not exist within str`,()=>{ + expect(countChar("aaaaa","b")).toEqual(0); +}); + // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..d4c4d5449 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,18 @@ function getOrdinalNumber(num) { - return "1st"; -} + if (num >=11 && num <= 19){ + return `${num}th` + }; + const lastDigit = num % 10 + switch (lastDigit) { + case 1: + return `${num}st`; + case 2: + return `${num}nd`; + case 3: + return `${num}rd`; + default: + return `${num}th`; + } +} module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560..1c62f3d38 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,23 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); +test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(132)).toEqual("132nd"); + }); + test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); + }); + test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(25)).toEqual("25th"); + expect(getOrdinalNumber(134)).toEqual("134th"); + }); + test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(18)).toEqual("18th"); + }); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..ae04a4f81 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,8 @@ -function repeatStr() { - return "hellohellohello"; -} +function repeatStr(times, str) { + if (times < 0){ throw ("error")} + return str.repeat(times); + +} + module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..f6c56819b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -10,23 +10,28 @@ const repeatStr = require("./repeat-str"); // Then it should return a string that contains the original `str` repeated `count` times. test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect (repeatStr(3 ,"hi")).toEqual("hihihi"); }); // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should when Given a target string `str` and a `count` equal to 1", () => { + expect (repeatStr(1 ,"hi")).toEqual("hi"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should when Given a target string `str` and a `count` equal to 0", () => { + expect (repeatStr(0 ,"hi")).toEqual(""); +}); + // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. + diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa..94339237d 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -1,17 +1,11 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. -let testName = "Jerry"; const greeting = "hello"; - function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); } - testName = "Aman"; - const greetingMessage = sayHello(greeting, testName); console.log(greetingMessage); // 'hello, Aman!' diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4..b1c2362d3 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,13 +2,8 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} - function countAndCapitalisePets(petsArr) { const petCount = {}; From b561db4e788cab884057f6e67a934ebb399757a6 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 22 Feb 2026 16:42:41 +0000 Subject: [PATCH 5/7] reset 1-imp... to main --- .../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, 25 insertions(+), 128 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 da091673d..9e05a871e 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,30 +15,9 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - 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 + // TODO: Implement this function } -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; @@ -51,7 +30,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 718f718a6..970cb9b64 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 (numerator >= denominator) { - return false; - } else { - return true; - } + // TODO: Implement this function } // The line below allows us to load the isProperFraction function into tests in other files. @@ -35,8 +31,3 @@ 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 ca9699157..c7559e787 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,33 +22,7 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - 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"; - } + // TODO: Implement this function } // The line below allows us to load the getCardValue function into tests in other files. @@ -56,10 +30,23 @@ 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. -//invalid card cases can you think of? +// 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? 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 55b22885c..d777f348d 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,31 +13,8 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(89)).toEqual("Acute angle"); }); -//Case 2: Right angle -test(`should return "Right angle" when (angle === 90)`, () => { - expect(getAngleType(90)).toEqual("Right angle"); -}); - +// Case 2: 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 d0148e1f9..7f087b2ba 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,19 +7,4 @@ 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 639ffa09e..cf7f9dae2 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,36 +7,14 @@ 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) -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"); +// Invalid Cards -}); // 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 e6c3c69727ea9e3ab083c79e9477e37ef90ae9ba Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 23 Feb 2026 10:27:49 +0000 Subject: [PATCH 6/7] should be done --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 3 +++ Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index d4c4d5449..aa02dc432 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,8 +1,10 @@ function getOrdinalNumber(num) { + if (num >=11 && num <= 19){ return `${num}th` }; + const lastDigit = num % 10 switch (lastDigit) { case 1: @@ -15,4 +17,5 @@ function getOrdinalNumber(num) { return `${num}th`; } } + module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index 1c62f3d38..0af0d1862 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -37,4 +37,4 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(14)).toEqual("14th"); expect(getOrdinalNumber(18)).toEqual("18th"); - }); \ No newline at end of file + }); From 7ae80a57d22b1dc73031b119ae89e1be10dbda44 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 23 Feb 2026 11:08:54 +0000 Subject: [PATCH 7/7] restored files not ment to be changed --- Sprint-3/3-dead-code/exercise-1.js | 6 ++++++ Sprint-3/3-dead-code/exercise-2.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 94339237d..4d09f15fa 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -1,11 +1,17 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. +let testName = "Jerry"; const greeting = "hello"; + function sayHello(greeting, name) { + const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; + console.log(greetingStr); } + testName = "Aman"; + const greetingMessage = sayHello(greeting, testName); console.log(greetingMessage); // 'hello, Aman!' diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index b1c2362d3..56d7887c4 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,8 +2,13 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); +function logPets(petsArr) { + petsArr.forEach((pet) => console.log(pet)); +} + function countAndCapitalisePets(petsArr) { const petCount = {};