diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..69932ca6d 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,"")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..9d8411b25 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -34,23 +34,35 @@ const right = getAngleType(90); assertEquals(right, "Right angle"); // Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, +// When the angle is less than 90 degrees,Add commentMore actions // Then the function should return "Acute angle" -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); + +test("should identify acute angles (e.g., 45°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(89.9)).toEqual("Acute angle"); +}); // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" -const obtuse = getAngleType(120); -// ====> write your test here, and then add a line to pass the test in the function above + +test("should identify obtuse angles (e.g., 90.1° and 179.9°)", () => { + expect(getAngleType (90.1)).toEqual("Obtuse angle"); + expect(getAngleType (179.9)).toEqual("Obtuse angle"); +}); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" -// ====> write your test here, and then add a line to pass the test in the function above +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file + +test("should identify reflex angles (180.1° and 359.9°)", () => { + expect(getAngleType(180.1)).toEqual("Reflex angle"); + expect(getAngleType (359.9)).toEqual("Reflex angle"); + }); diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..3a8597095 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -40,6 +40,7 @@ assertEquals(improperFraction, false); // target output: true // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); +assertEquals(properFraction, true); // ====> complete with your assertion // Equal Numerator and Denominator check: @@ -51,3 +52,17 @@ const equalFraction = isProperFraction(3, 3); // Stretch: // What other scenarios could you test for? +// fraction is true because the absolute value of the numerator (0) is less than the denominator (5). +assertEquals(isProperFraction (0, 5), true) + +// fraction is fa;se because the absolute value of the numerator (3) is greater than the denominator (0). +assertEquals(isProperFraction(3, 0), false); + +// fraction is true because the absolute value of the numerator (2) is less than the denominator (-5). +assertEquals(isProperFraction(2, -5), true); + +// fraction is false because the absolute value of the numerator (-3) is greater than the denominator (-4). +assertEquals(isProperFraction(-3, -4), false); + +// fraction is true because the absolute value of the numerator (-9) is less than the denominator (5). +assertEquals(isProperFraction(-9, 5), false); \ No newline at end of file diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..15af943f5 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -7,6 +7,7 @@ // complete the rest of the tests and cases // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers +// if (rank === "A") return 11; function getCardValue(card) { if (rank === "A") return 11; } @@ -33,19 +34,44 @@ assertEquals(aceofSpades, 11); // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); +assertEquals(fiveofHearts, 5); +const sevenofspades = getCardValue("7♠"); +assertEquals(sevenofspades , 7); +const eightofHearts = getCardValue("8♥"); +assertEquals(eightofHearts, 8); +const nineofdiamonds = getCardValue("9♦"); +assertEquals(nineofdiamonds, 9); + // ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const tenofSpades = getCardValue("10♠"); +assertEquals(tenofSpades("10♠"), 10); +const jackofspades = getCardValue("J♠"); +assertEquals(jackofspades("J♠"), 10); +const Queenofhearts = getCardValue("Q♥"); +assertEquals(Queenofhearts("Q♥"), 10); +const Kingofhearts = getCardValue("K♥"); +assertEquals(Kingofhearts ("K♥"), 10); + + // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const AceCard = getCardValue("A"); +assertEquals(AceCard ("A"), 11); // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + +const invalidCards = ["Z♠", "11", "Y♠", "1♣"]; +for (const card of invalidCards) { + assertEquals(error.message, "Invalid card rank"); +} \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..93e872999 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,16 +1,26 @@ function getAngleType(angle) { - if (angle === 90) return "Right angle"; - // replace with your completed function from key-implement - + // Ensure angle is a number and within valid bounds + if (typeof angle !== "number" || angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + if (angle < 90) { + return "Acute angle"; + } + if (angle === 90) { + return "Right angle"; + } + if (angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } + // Any remaining angle must be between 180 and 360 (exclusive) + return "Reflex angle"; } - - - - - // Don't get bogged down in this detail // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..dfd482882 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -11,14 +11,32 @@ test("should identify right angle (90°)", () => { // When the angle is less than 90 degrees, // Then the function should return "Acute angle" +test("should identify acute angles (e.g., 45°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(89.9)).toEqual("Acute angle"); +}); + // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify obtuse angles (e.g., 90.1° and 179.9°)", () => { + expect(getAngleType (90.1)).toEqual("Obtuse angle"); + expect(getAngleType (179.9)).toEqual("Obtuse angle"); +}); + // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" + +test("should identify reflex angles (180.1° and 359.9°)", () => { + expect(getAngleType(180.1)).toEqual("Reflex angle"); + expect(getAngleType (359.9)).toEqual("Reflex angle"); +}); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..63c51b36f 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,11 @@ + function isProperFraction(numerator, denominator) { - if (numerator < denominator) return true; - // add your completed function from key-implement here + // Check for invalid fraction (denominator cannot be zero) + if (denominator === 0) { + return false; + } + // Check if the absolute value of the numerator is less than the absolute value of the denominator + return Math.abs(numerator) < Math.abs(denominator); } -module.exports = isProperFraction; \ No newline at end of file +module.exports = isProperFraction; diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..08d5b7781 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for a Improper fraction", () => { + expect(isProperFraction(5, 3)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return true for negative fraction", () => { + expect(isProperFraction(-2, 3)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return false for equal numerator and denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..22d4c5998 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,14 @@ function getCardValue(card) { - // replace with your code from key-implement - return 11; + const rank = card.slice(0, -1); // strip off the suit emoji + + if (rank === "A") return 11; + if (["K", "Q", "J", "10"].includes(rank)) return 10; + + // Accept only exact digits 2 through 9 + if (/^[2-9]$/.test(rank)) { + return Number(rank); + } + throw new Error("Invalid card rank"); } -module.exports = getCardValue; \ No newline at end of file +module.exports = getCardValue; + \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..b8c060e97 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -5,7 +5,33 @@ test("should return 11 for Ace of Spades", () => { expect(aceofSpades).toEqual(11); }); -// Case 2: Handle Number Cards (2-10): -// Case 3: Handle Face Cards (J, Q, K): -// Case 4: Handle Ace (A): -// Case 5: Handle Invalid Cards: + +// Case 2: Handle Number Cards (2-10) +test("should return the value of number cards (2-10)", () => { + const testCases = [ + ["2♣", 2], + ["5♠", 5], + ["10♦", 10] + ]; + testCases.forEach(([card, expected]) => { + expect(getCardValue(card)).toEqual(expected); + }); +}); + +test("should return 10 for 10 of Diamonds", () => { + const ten = getCardValue("10♦"); + expect(ten).toEqual(10); +}); + +// Case 3: Handle Face Cards (J, Q, K) +test("should return 10 for face cards J, Q, K", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♣")).toEqual(10); + expect(getCardValue("K♥")).toEqual(10); +}); + +// Case 5: Handle Invalid Cards +test("should throw error for invalid card Z♠", () => { + expect(() => getCardValue("Z♠")).toThrow("Invalid card rank"); +}); + diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..5777801e9 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } + } + return count; } -module.exports = countChar; \ No newline at end of file +module.exports = countChar; diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..12808648f 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -1,5 +1,5 @@ // 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: @@ -9,6 +9,7 @@ const countChar = require("./count"); // And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'), // When the function is called with these inputs, // Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa'). +const countChar = require("./count"); test("should count multiple occurrences of a character", () => { const str = "aaaaa"; @@ -22,3 +23,10 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. + +test("should return 0 if the character does not exist in the string", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js deleted file mode 100644 index 24f528b0d..000000000 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ /dev/null @@ -1,5 +0,0 @@ -function getOrdinalNumber(num) { - return "1st"; -} - -module.exports = getOrdinalNumber; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..b53341af9 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -1,13 +1,35 @@ -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 -// Case 1: Identify the ordinal number for 1 -// When the number is 1, -// Then the function should return "1st" +const getOrdinalNumber = require("./getOrdinalNumber"); -test("should return '1st' for 1", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - }); +test("returns 1st for 1", () => { + expect(getOrdinalNumber(1)).toBe("1st"); +}); + + test("returns 2nd for 2", () => { + expect(getOrdinalNumber(2)).toBe("2nd"); +}); + +test("returns 3rd for 3", () => { + expect(getOrdinalNumber(3)).toBe("3rd"); +}); + +test("returns 4th for 4", () => { + expect(getOrdinalNumber(4)).toBe("4th"); +}); + +test("Handle the special case for teens (11, 12, 13)", () => { + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + expect(getOrdinalNumber(13)).toBe("13th"); +}); + +test("Get the last digit to determine suffix", () => { + expect(getOrdinalNumber(21)).toBe("21st"); + expect(getOrdinalNumber(22)).toBe("22nd"); + expect(getOrdinalNumber(23)).toBe("23rd"); + expect(getOrdinalNumber(101)).toBe("101st"); +}); diff --git a/Sprint-3/3-mandatory-practice/implement/getOrdinalNumber.js b/Sprint-3/3-mandatory-practice/implement/getOrdinalNumber.js new file mode 100644 index 000000000..9ce5a7cf3 --- /dev/null +++ b/Sprint-3/3-mandatory-practice/implement/getOrdinalNumber.js @@ -0,0 +1,20 @@ +function getOrdinalNumber(num) { + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + } + + 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/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..3b7a40ffe 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,9 @@ -function repeat() { - return "hellohellohello"; +function repeat(str = "", count = 1) { + if (count < 0) { + throw new Error("Invalid count"); + } + + return str.repeat(count); } -module.exports = repeat; \ No newline at end of file +module.exports = repeat; diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..d2d675533 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -30,3 +30,34 @@ test("should repeat the string count times", () => { // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + +// Case: Repeat string multiple times +test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hellohellohello"); +}); + +// Case: Handle count of 1 +test("should return the original string if count is 1", () => { + const str = "test"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("test"); +}); + +// Case: Handle count of 0 +test("should return an empty string if count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); + +// Case: Negative count +test("should throw an error if count is negative", () => { + const str = "hello"; + const count = -2; + expect(() => repeat(str, count)).toThrow("Invalid count"); +}); diff --git a/Sprint-3/4-stretch-investigate/card-validator.js b/Sprint-3/4-stretch-investigate/card-validator.js new file mode 100644 index 000000000..ee1d5ea3e --- /dev/null +++ b/Sprint-3/4-stretch-investigate/card-validator.js @@ -0,0 +1,32 @@ +function validateCreditCard(cardNumber) { + // Check length and numeric characters + if (cardNumber.length !== 16 || !/^\d{16}$/.test(cardNumber)) { + return false; + } + + // Check at least two different digits + const uniqueDigits = new Set(cardNumber); + if (uniqueDigits.size < 2) { + return false; + } + + // Check last digit is even + const lastDigit = Number(cardNumber[cardNumber.length - 1]); + if (lastDigit % 2 !== 0) { + return false; + } + + // Check sum of digits + let digitSum = 0; + for (let digit of cardNumber) { + digitSum += Number(digit); + } + if (digitSum <= 16) { + return false; + } + + // If all checks passed, return true + return true; +} + +module.exports = validateCreditCard; diff --git a/Sprint-3/4-stretch-investigate/card-validator.md b/Sprint-3/4-stretch-investigate/card-validator.md index e39c6ace6..da0aa654d 100644 --- a/Sprint-3/4-stretch-investigate/card-validator.md +++ b/Sprint-3/4-stretch-investigate/card-validator.md @@ -33,3 +33,6 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! + + + diff --git a/Sprint-3/4-stretch-investigate/find.js b/Sprint-3/4-stretch-investigate/find.js index c7e79a2f2..b34382ead 100644 --- a/Sprint-3/4-stretch-investigate/find.js +++ b/Sprint-3/4-stretch-investigate/find.js @@ -18,8 +18,19 @@ console.log(find("code your future", "z")); // Use the Python Visualiser to help you play computer with this example and observe how this code is executed // Pay particular attention to the following: +/* a) how does the index variable update during the call to find? +index starts at 0, and it increases by 1 on each loop iteration using index++. +It keeps track of the current position in the string as you check each character. -// a) How the index variable updates during the call to find -// b) What is the if statement used to check -// c) Why is index++ being used? -// d) What is the condition index < str.length used for? +b) What is the if statement used to check +This checks whether the character at the current index matches the target character. +If it does, the function returns the index and stops running. + +c) Why is index++ being used? +index++ increments the index by 1 after each check, so the loop continues moving forward through the string. +Without this, the loop would get stuck on the same character instead of running through the rest of the string. + +d) What is the condition index < str.length used for? +This ensures the loop runs only while index is within the bounds of the string. +It prevents accessing characters beyond the end of the string. +*/ diff --git a/Sprint-3/4-stretch-investigate/password-validator.js b/Sprint-3/4-stretch-investigate/password-validator.js index b55d527db..9ebd413b8 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.js +++ b/Sprint-3/4-stretch-investigate/password-validator.js @@ -1,6 +1,29 @@ +const previousPasswords = ["Password123!", "Welcome1$", "Admin#2023"]; // example previous passwords list + function passwordValidator(password) { - return password.length < 5 ? false : true -} + + // Check that password is a string + if (typeof password !== "string") return false; + // Check minimum length + if (password.length < 5) return false; + + // Check for at least one uppercase letter + if (!/[A-Z]/.test(password)) return false; + + // Check for at least one lowercase letter + if (!/[a-z]/.test(password)) return false; + // Check for at least one digit + if (!/[0-9]/.test(password)) return false; + + // Check for at least one special character from allowed set + if (!/[!#$%.*&]/.test(password)) return false; + + // Check password not previously used + if (previousPasswords.includes(password)) return false; + + // If all checks pass, password is valid + return true; +} -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; diff --git a/Sprint-3/4-stretch-investigate/password-validator.test.js b/Sprint-3/4-stretch-investigate/password-validator.test.js index 8fa3089d6..7e91b3c36 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.test.js +++ b/Sprint-3/4-stretch-investigate/password-validator.test.js @@ -14,13 +14,34 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ -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); -} -); \ No newline at end of file + // Assert + +const passwordValidator= require("./password-validator"); + + test("Password must be at least 5 characters long.", () => { + expect(passwordValidator("St1!")).toBe(false); +}); + + test("password with exactly 5 valid characters long", () => { + expect(isValidPassword("Stg1!")).toBe(true); +}); + test("Password must include at least one uppercase letter.", () =>{ + expect(passwordValidator("strong1!")).toBe(false); + } ) + + test("Password must include at least one lowercase letter.", () =>{ + expect(passwordValidator("STRONG1")).toBe(false); + } ) + + test("Password must include at least one number.", () =>{ + expect(passwordValidator("Strong*")).toBe(false); + } ) + + test("Password must include at least one special symbol (!#$%.*&).", () =>{ + expect(passwordValidator("Strong2")).toBe(false); + } ) + + test("This password has already been used. Please choose a new one.", () =>{ + expect(passwordValidator("Password123!")).toBe(false); + + })