diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..719fddbefa 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -3,3 +3,9 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; + test( "should count multiple occurrences of a character ", function(){ + const stringofcharacters = "aaaaa"; + const findcharcaters = "a"; + const count = countChar(stringofcharacters, findcharcaters); + expect(count).toEqual(5); + }); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..7c494f3337 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -3,6 +3,15 @@ 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: +function CountChar(str, char) { + let count = 0; + for (let i = 0; i < str.length; i++) { + if (str[i] === char) { + count++; + } + } + return count; +} // Scenario: Multiple Occurrences // Given the input string `str`, @@ -22,3 +31,9 @@ test("should count multiple occurrences of a character", () => { // 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. +test('should return 0 when the character does not occur in the string', () => { + const str = "hello"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..e56ce47b94 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -3,3 +3,13 @@ function getOrdinalNumber(num) { } module.exports = getOrdinalNumber; + test(`works with any number ending with 1, except for 11. For all other numbers, it should return the number followed by "th" with exceptions to 2 and 3 `, () => { + expect(getOrdinalNumber(1)).toBe("1st"); + expect(getOrdinalNumber(2)).toBe("2nd"); + expect(getOrdinalNumber(3)).toBe("3rd"); + expect(getOrdinalNumber(4)).toBe("4th"); + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + }); + + \ No newline at end of file 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..1df44e4458 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -15,6 +15,18 @@ const getOrdinalNumber = require("./get-ordinal-number"); // 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(31)).toEqual("31st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + 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 'rd' for numbers ending with 3 except those ending with 13 `, () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(143)).toEqual("143rd"); +}); + \ No newline at end of file