From 8d04f46eea52e5f42aef8c3898edbd2ff5165d81 Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Wed, 4 Mar 2026 13:09:03 +0000 Subject: [PATCH 1/3] Complete implement and rewrite tests for Sprint 3 --- .../1-implement-and-rewrite-tests/README.md | 8 +-- .../implement/1-get-angle-type.js | 46 ++++++++++++++- .../implement/2-is-proper-fraction.js | 20 ++++++- .../implement/3-get-card-value.js | 59 +++++++++++++++++-- .../1-get-angle-type.test.js | 21 ++++++- .../2-is-proper-fraction.test.js | 21 +++++++ .../3-get-card-value.test.js | 22 ++++++- Sprint-3/2-practice-tdd/count.js | 11 +++- Sprint-3/2-practice-tdd/count.test.js | 6 ++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 16 ++++- .../2-practice-tdd/get-ordinal-number.test.js | 40 +++++++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 25 +++++++- Sprint-3/2-practice-tdd/repeat-str.test.js | 19 +++++- Sprint-3/3-dead-code/exercise-1.js | 17 ++---- Sprint-3/3-dead-code/exercise-2.js | 11 +--- Sprint-3/3-dead-code/newFile.js | 3 + Sprint-3/4-stretch/find.js | 9 +++ Sprint-3/4-stretch/password-validator.js | 32 +++++++++- Sprint-3/4-stretch/password-validator.test.js | 35 +++++++++-- package.json | 1 + 20 files changed, 375 insertions(+), 47 deletions(-) create mode 100644 Sprint-3/3-dead-code/newFile.js diff --git a/Sprint-3/1-implement-and-rewrite-tests/README.md b/Sprint-3/1-implement-and-rewrite-tests/README.md index a65bd2077c..876ff4cc4c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/README.md +++ b/Sprint-3/1-implement-and-rewrite-tests/README.md @@ -5,14 +5,14 @@ to choose test values that thoroughly test a function. ## 1 Implement solutions -In the `implement` directory you've got a number of functions you'll need to implement. + +Here is a recommended order: + +1. `1-get-angle-type.js`In the `implement` directory you've got a number of functions you'll need to implement. For each function, you also have a number of different cases you'll need to check for your function. Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step. -Here is a recommended order: - -1. `1-get-angle-type.js` 2. `2-is-proper-fraction.js` 3. `3-get-card-value.js` 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..a2ddc0d277 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,30 @@ // 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. @@ -33,5 +56,24 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -const right = getAngleType(90); +let invalid = getAngleType(0); +assertEquals(invalid, "Invalid angle"); +let acute = getAngleType(1); +assertEquals(acute, "Acute angle"); + acute = getAngleType(89); +assertEquals(acute, "Acute angle"); +let right= getAngleType(90); assertEquals(right, "Right angle"); +let obtuse = getAngleType(91); +assertEquals(obtuse, "Obtuse angle"); +obtuse = getAngleType(179); +assertEquals(obtuse, "Obtuse angle"); +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); +let reflex = getAngleType(181); +assertEquals(reflex, "Reflex angle"); +reflex = getAngleType(359); +assertEquals(reflex, "Reflex angle"); + invalid = getAngleType(400); +assertEquals(invalid, "Invalid 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..940ed69acb 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,18 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0){ + return false; + } + else if (numerator < denominator) + { + return true; + + } + else + { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +42,10 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(5, 4), false); +assertEquals(isProperFraction(3, 3), false); +assertEquals(isProperFraction(0, 5), true); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(-3, 2), true); +assertEquals(isProperFraction(2, -5), false); +assertEquals(isProperFraction(-2, -3), false); \ 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 c7559e787e..5586b9f134 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,37 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if(typeof card !== "string" || card.length<2) + { + throw new Error("Invalid card"); + } + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]; + + if(!validSuits.includes(suit) || !validRanks.includes(rank)) + { + throw new Error("Invalid card"); + } + else if (rank == "A") + { + return 11; + } + else if (["J","Q","K"].includes(rank)) +{ + 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; module.exports = getCardValue; - // Helper functions to make our assertions easier to read. function assertEquals(actualOutput, targetOutput) { console.assert( @@ -40,13 +64,40 @@ 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("K♦"), 10); +assertEquals(getCardValue("10♥"), 10); // Handling invalid cards try { - getCardValue("invalid"); + getCardValue("11♠"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} +try { + getCardValue("A?"); +console.error("Error was not thrown for invalid card"); +} catch (e) {} +try { + getCardValue("A"); - // This line will not be reached if an error is thrown as expected + + console.error("Error was not thrown for invalid card"); +} catch (e) {} +try { + getCardValue("10"); + + console.error("Error was not thrown for invalid card"); } catch (e) {} // What other invalid card cases can you think of? +//try { + //getCardValue("AA"); +//console.error("Error was not thrown for invalid card"); +//} catch (e) {} +//try { + //getCardValue("1♠"); + + + //console.error("Error was not thrown for invalid card"); +//} catch (e) {} \ 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..efd6ff2c97 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 @@ -9,9 +9,28 @@ const getAngleType = require("../implement/1-get-angle-type"); test(`should return "Acute angle" when (0 < angle < 90)`, () => { // Test various acute angles, including boundary cases expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); + //expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); }); +test(`should return "Right angle" when (angle = 90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(90)).toEqual("Right angle"); +}); +test(`should return"Obtuse angle" when (90 < angle< 180)`, ()=>{ + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); +test(`should return "Straight angle" when ( angle = 180)`,()=>{ + expect(getAngleType(180)).toEqual("Straight angle"); +}); +test(`should return "Reflex angle" when (180 < angle <360)`, ()=>{ + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); + +}); +test(`should return "invalid angle when angles outside the valid range`, ()=>{ + expect(getAngleType(0)).toEqual("Invalid angle") +}) // Case 2: Right angle // Case 3: Obtuse angles 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..283975aa5b 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 @@ -8,3 +8,24 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +test(`Should return true when numerator is zero`, ()=>{ + expect(isProperFraction(0, 5)).toEqual(true); +}); +test(`should return true when denominator is greater than numerator`, () =>{ +expect(isProperFraction(1, 2)).toEqual(true); +}); +test(`should return false when numerator is greater than denominator`, ()=> { + expect(isProperFraction(5, 4)).toEqual(false); +}); +test(`should return false when numerator is equals to denominator`, ()=>{ +expect(isProperFraction(3, 3)).toEqual(false); +}); +test(`should return true when denominator is greater than negative numerator`, ()=>{ + expect(isProperFraction(-3, 2)).toEqual(true); +}); +test(`should return false when numerator is greater than denominator`, ()=> { + expect(isProperFraction(2, -5)).toEqual(false); +}); +test(`should return false when negative numerator is greater than negative denominator`, ()=> { + expect(isProperFraction(-2, -3)).toEqual(false); +}); 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..d58ba3d71e 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 @@ -8,7 +8,27 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); - +test(`should return 9 when given a 9♠ card`,()=>{ + expect(getCardValue("9♠")).toEqual(9); +}); +test (`should return 10 when given a face card K♦`, ()=>{ + expect(getCardValue("K♦")).toEqual(10); +}); +test(`should return 10 when given a 10`, ()=>{ + expect(getCardValue("10♥")).toEqual(10); +}); +test(`should throw error for invalid Ranks`, ()=>{ + expect(()=> getCardValue("11♠")).toThrow(); +}); +test(`should throw error for invalid Suits`, ()=>{ + expect(()=> getCardValue("A?")).toThrow(); +}); +test(`should throw error for missing Suits`,()=>{ + expect(()=> getCardValue("A")).toThrow(); +}); +test(`should throw error for non String input`, ()=>{ + expect(()=> getCardValue("10")).toThrow(); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..01f3e4aaf9 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,12 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + let count = 0; + for (let i = 0; i < str.length; i++) + if(str[i] === char) + { + count++; + } + return count; } + module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..ab0474c0b1 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -16,6 +16,12 @@ test("should count multiple occurrences of a character", () => { const count = countChar(str, char); expect(count).toEqual(5); }); +test("should count no occurrences of a character",()=>{ + const str = "hello"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); // Scenario: No Occurrences // Given the input string `str`, diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..51b52cb112 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,19 @@ function getOrdinalNumber(num) { - return "1st"; + if( num%10 === 1 && num%100 !== 11) + { + return `${num}st`; + } + else if (num%10 === 2 && num%100 !== 12) + { + return `${num}nd`; + } + else if(num%10===3 && num%100 !==13) + { + return `${num}rd`; + } + else{ + 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 adfa58560f..8a64c8d5c9 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,43 @@ 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 'th' for numbers ending with 11", ()=>{ + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(211)).toEqual("211th"); + expect(getOrdinalNumber(311)).toEqual("311th"); +}); +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(132)).toEqual("132nd"); +}); +test("should append 'th' for numbers ending with 12", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(212)).toEqual("212th"); +}); + +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); +test("should append 'th' for numbers ending with 13", () => { + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(113)).toEqual("113th"); + expect(getOrdinalNumber(213)).toEqual("213th"); +}); +test("should append 'th' for numbers ending with 4", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(134)).toEqual("134th"); +}); + + + + + + + + diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..2b40fca45e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,26 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count <0) + { + throw new Error("negative counts are not valid"); + } + else if(count === 1) + { + return str; + } + else if (count === 0) + { + return ""; + } + else + { + let result =""; + for (let i =0; i { const str = "hello"; const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect(repeatStr(str,count)).toEqual("hellohellohello"); +}); +test(" should return original 'str' without repetition", ()=>{ + const str = "hello"; + const count = 1; + expect(repeatStr(str, count)).toEqual("hello"); +}); +test("should return empty string", ()=>{ + const str = "hello"; + const count = 0; + expect(repeatStr(str, count)).toEqual(""); + +}); +test("should throw negative counts are not valid Error", ()=>{ +const str = "hello"; + const count = -1; + expect(()=> repeatStr(str, count)).toThrow(); }); // Case: handle count of 1: diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..9952624e50 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -1,17 +1,12 @@ // 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); +export function sayHello(greeting, name) { +return `${greeting}, ${name}!`; -console.log(greetingMessage); // 'hello, Aman!' +} +console.log(sayHello("hello", "Aman")); +console.log(sayHello("hello", "Arun")); +console.log(sayHello("hello", "Harini")); \ No newline at end of file diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..02612aff87 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -1,14 +1,9 @@ // Remove the unused code that does not contribute to the final console log -// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. + //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 = {}; @@ -23,6 +18,4 @@ function countAndCapitalisePets(petsArr) { return petCount; } -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countAndCapitalisePets(petsStartingWithH)); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log diff --git a/Sprint-3/3-dead-code/newFile.js b/Sprint-3/3-dead-code/newFile.js new file mode 100644 index 0000000000..ff5c700b6a --- /dev/null +++ b/Sprint-3/3-dead-code/newFile.js @@ -0,0 +1,3 @@ +const { sayHello } = require("./exercise-1"); + +console.log(sayHello("hello , ", Arun, "));")); diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index c7e79a2f21..f554e0e93d 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -20,6 +20,15 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +// index starts at 0. +// The while loop runs as long as index is less than the string length. +// Inside the loop, if the character at index matches the target, the function returns that index. +// If it does not match, index increases by 1 and the loop checks again. +// This continues until the character is found or the end of the string is reached. // b) What is the if statement used to check +// The if statement checks the character at the current index, and if it matches the target character, it returns the character index (position in the string). // c) Why is index++ being used? +// index++ increases the index by 1 so the loop can check the next character in the string. // d) What is the condition index < str.length used for? +// index < str.length ensures the loop runs only while the index is within the string length. +// It stops the loop when the end of the string is reached. diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527dba..315d62678e 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,5 +1,35 @@ function passwordValidator(password) { - return password.length < 5 ? false : true + const previousPassword =["Arun!1621"]; + const specialChar = ["!", "#", "$", "%", ".", "*", "&"]; + if (password.length<5) + { + throw new Error("minimum length is 5"); + } + else if(!/[A-Z]/.test(password)) + { + throw new Error("Need at least one uppercase"); + } + else if (!/[a-z]/.test(password)) + { + throw new Error("Need at least one lower case"); + } + else if (!/[0-9]/.test(password)) + { + throw new Error("need at least one number"); + } + else if(!/["!", "#", "$", "%", ".", "*", "&"]/.test(password)) + { + throw new Error("need at least one special character"); + } + else if (previousPassword.includes(password)) + { + throw new Error("no previous password"); + + } +else +{ + return true; +} } diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6b..f5b462e229 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -17,10 +17,33 @@ You must breakdown this problem in order to solve it. Find one test case first a const isValidPassword = require("./password-validator"); test("password has at least 5 characters", () => { // Arrange - const password = "12345"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); + const password = "Ha!1"; + expect( ()=> isValidPassword(password)).toThrow(); } -); \ No newline at end of file +); +test("password has at least one uppercase letter(A-Z)",()=>{ +const password = "harju!1621"; + + + expect(()=> isValidPassword(password)).toThrow(); +}); +test("password has at least one lowercase letter (a-z)", ()=>{ + const password = "HARJU!1621"; + expect(()=> isValidPassword(password)).toThrow(); +}); +test("password has at least one number (0-9)", ()=>{ + const password = "Harju!"; + expect(()=>isValidPassword(password)).toThrow(); +}); +test("password has at least one special character ",()=>{ + const password = "Harju1621"; + expect(()=> isValidPassword(password)).toThrow(); +}); +test("password not match with previous password", ()=>{ + const password = "Arun!1621"; + expect(()=> isValidPassword(password)).toThrow(); +}); +test("password meet all the condition", ()=>{ + const password ="Harju!1621"; + expect(isValidPassword(password)).toEqual(true); +}); \ No newline at end of file diff --git a/package.json b/package.json index 0657e22dd8..88a5188578 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "module-structuring-and-testing-data", + "type": "module", "version": "1.0.0", "description": "Like learning a musical instrument, programming requires daily practice.", "main": "index.js", From c7b3477310cd9c21c5217a6f6e7a398497b4170a Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Wed, 4 Mar 2026 13:11:34 +0000 Subject: [PATCH 2/3] Remove practice-tdd folder from implement PR --- Sprint-3/2-practice-tdd/README.md | 13 ---- Sprint-3/2-practice-tdd/count.js | 12 ---- Sprint-3/2-practice-tdd/count.test.js | 30 ---------- Sprint-3/2-practice-tdd/get-ordinal-number.js | 19 ------ .../2-practice-tdd/get-ordinal-number.test.js | 60 ------------------- Sprint-3/2-practice-tdd/repeat-str.js | 26 -------- Sprint-3/2-practice-tdd/repeat-str.test.js | 47 --------------- 7 files changed, 207 deletions(-) delete mode 100644 Sprint-3/2-practice-tdd/README.md delete mode 100644 Sprint-3/2-practice-tdd/count.js delete mode 100644 Sprint-3/2-practice-tdd/count.test.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.js delete mode 100644 Sprint-3/2-practice-tdd/get-ordinal-number.test.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.js delete mode 100644 Sprint-3/2-practice-tdd/repeat-str.test.js diff --git a/Sprint-3/2-practice-tdd/README.md b/Sprint-3/2-practice-tdd/README.md deleted file mode 100644 index f7d82fe43d..0000000000 --- a/Sprint-3/2-practice-tdd/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Practice TDD - -In this section you'll practice this key skill of building up your program test first. - -Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. - -Write the tests _before_ the code that will make them pass. - -Recommended order: - -1. `count.test.js` -1. `repeat-str.test.js` -1. `get-ordinal-number.test.js` diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js deleted file mode 100644 index 01f3e4aaf9..0000000000 --- a/Sprint-3/2-practice-tdd/count.js +++ /dev/null @@ -1,12 +0,0 @@ -function countChar(str, char) { - let count = 0; - for (let i = 0; i < str.length; i++) - if(str[i] === char) - { - count++; - } - return count; -} - - -module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js deleted file mode 100644 index ab0474c0b1..0000000000 --- a/Sprint-3/2-practice-tdd/count.test.js +++ /dev/null @@ -1,30 +0,0 @@ -// implement a function countChar that counts the number of times a character occurs in a string -const countChar = require("./count"); -// Given a string `str` and a single character `char` to search for, -// When the countChar function is called with these inputs, -// Then it should: - -// Scenario: Multiple Occurrences -// Given the input string `str`, -// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), -// When the function is called with these inputs, -// Then it should correctly count occurrences of `char`. - -test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); -}); -test("should count no occurrences of a character",()=>{ - const str = "hello"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(0); -}); - -// Scenario: No Occurrences -// Given the input string `str`, -// And a character `char` that does not exist within `str`. -// 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 deleted file mode 100644 index 51b52cb112..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,19 +0,0 @@ -function getOrdinalNumber(num) { - if( num%10 === 1 && num%100 !== 11) - { - return `${num}st`; - } - else if (num%10 === 2 && num%100 !== 12) - { - return `${num}nd`; - } - else if(num%10===3 && num%100 !==13) - { - return `${num}rd`; - } - else{ - 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 deleted file mode 100644 index 8a64c8d5c9..0000000000 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ /dev/null @@ -1,60 +0,0 @@ -const getOrdinalNumber = require("./get-ordinal-number"); -// In this week's prep, we started implementing getOrdinalNumber. - -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. - -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// Instead of writing tests for individual numbers, consider grouping all possible input values -// into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. - -// Case 1: Numbers ending with 1 (but not 11) -// When the number ends with 1, except those ending with 11, -// Then the function should return a string by appending "st" to the number. -test("should append 'st' for numbers ending with 1, except those ending with 11", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - expect(getOrdinalNumber(21)).toEqual("21st"); - expect(getOrdinalNumber(131)).toEqual("131st"); -}); -test("should append 'th' for numbers ending with 11", ()=>{ - expect(getOrdinalNumber(11)).toEqual("11th"); - expect(getOrdinalNumber(111)).toEqual("111th"); - expect(getOrdinalNumber(211)).toEqual("211th"); - expect(getOrdinalNumber(311)).toEqual("311th"); -}); -test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { - expect(getOrdinalNumber(2)).toEqual("2nd"); - expect(getOrdinalNumber(22)).toEqual("22nd"); - expect(getOrdinalNumber(132)).toEqual("132nd"); -}); -test("should append 'th' for numbers ending with 12", () => { - expect(getOrdinalNumber(12)).toEqual("12th"); - expect(getOrdinalNumber(112)).toEqual("112th"); - expect(getOrdinalNumber(212)).toEqual("212th"); -}); - -test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { - expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(33)).toEqual("33rd"); - expect(getOrdinalNumber(133)).toEqual("133rd"); -}); -test("should append 'th' for numbers ending with 13", () => { - expect(getOrdinalNumber(13)).toEqual("13th"); - expect(getOrdinalNumber(113)).toEqual("113th"); - expect(getOrdinalNumber(213)).toEqual("213th"); -}); -test("should append 'th' for numbers ending with 4", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(14)).toEqual("14th"); - expect(getOrdinalNumber(134)).toEqual("134th"); -}); - - - - - - - - diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js deleted file mode 100644 index 2b40fca45e..0000000000 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ /dev/null @@ -1,26 +0,0 @@ -function repeatStr(str, count) { - if (count <0) - { - throw new Error("negative counts are not valid"); - } - else if(count === 1) - { - return str; - } - else if (count === 0) - { - return ""; - } - else - { - let result =""; - for (let i =0; i { - const str = "hello"; - const count = 3; - expect(repeatStr(str,count)).toEqual("hellohellohello"); -}); -test(" should return original 'str' without repetition", ()=>{ - const str = "hello"; - const count = 1; - expect(repeatStr(str, count)).toEqual("hello"); -}); -test("should return empty string", ()=>{ - const str = "hello"; - const count = 0; - expect(repeatStr(str, count)).toEqual(""); - -}); -test("should throw negative counts are not valid Error", ()=>{ -const str = "hello"; - const count = -1; - expect(()=> repeatStr(str, count)).toThrow(); -}); - -// 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. - -// 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. - -// 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. From 83977219e040688ba35e29397445e09471c5ac02 Mon Sep 17 00:00:00 2001 From: Arunkumar Akilan Date: Wed, 4 Mar 2026 14:36:01 +0000 Subject: [PATCH 3/3] Remove practice-tdd and dead-code from implement PR --- Sprint-3/3-dead-code/README.md | 9 --------- Sprint-3/3-dead-code/exercise-1.js | 12 ------------ Sprint-3/3-dead-code/exercise-2.js | 21 --------------------- Sprint-3/3-dead-code/newFile.js | 3 --- 4 files changed, 45 deletions(-) delete mode 100644 Sprint-3/3-dead-code/README.md delete mode 100644 Sprint-3/3-dead-code/exercise-1.js delete mode 100644 Sprint-3/3-dead-code/exercise-2.js delete mode 100644 Sprint-3/3-dead-code/newFile.js diff --git a/Sprint-3/3-dead-code/README.md b/Sprint-3/3-dead-code/README.md deleted file mode 100644 index 2bfbfff819..0000000000 --- a/Sprint-3/3-dead-code/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Refactoring Dead Code - -Here are two example of code that has not been built efficiently. Both files have dead code in them. It's your job to go back through this existing code, identify the dead code, and remove it so the code is ready for production. - -## Instructions - -1. Work through each `exercise` file inside this directory. -2. Delete the dead code. -3. Commit your changes and make a PR when done. diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js deleted file mode 100644 index 9952624e50..0000000000 --- a/Sprint-3/3-dead-code/exercise-1.js +++ /dev/null @@ -1,12 +0,0 @@ -// Find the instances of unreachable and redundant code - remove them! -// The sayHello function should continue to work for any reasonable input it's given. - - - -export function sayHello(greeting, name) { -return `${greeting}, ${name}!`; - -} -console.log(sayHello("hello", "Aman")); -console.log(sayHello("hello", "Arun")); -console.log(sayHello("hello", "Harini")); \ No newline at end of file diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js deleted file mode 100644 index 02612aff87..0000000000 --- a/Sprint-3/3-dead-code/exercise-2.js +++ /dev/null @@ -1,21 +0,0 @@ -// Remove the unused code that does not contribute to the final console log - //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 petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - -function countAndCapitalisePets(petsArr) { - const petCount = {}; - - petsArr.forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - return petCount; -} - -console.log(countAndCapitalisePets(petsStartingWithH)); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log diff --git a/Sprint-3/3-dead-code/newFile.js b/Sprint-3/3-dead-code/newFile.js deleted file mode 100644 index ff5c700b6a..0000000000 --- a/Sprint-3/3-dead-code/newFile.js +++ /dev/null @@ -1,3 +0,0 @@ -const { sayHello } = require("./exercise-1"); - -console.log(sayHello("hello , ", Arun, "));"));