Skip to content

Commit 1ec2362

Browse files
committed
delete the unwanted declaration , add some testing scenarios on the count.js file and provide detail descriptions on the repeat .js file
1 parent b470944 commit 1ec2362

3 files changed

Lines changed: 37 additions & 20 deletions

File tree

Sprint-3/2-practice-tdd/count.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
let count = 0;
3-
str = stringOfCharacters
4-
char = findCharacter
5-
for (let i = 0; i < str.length; i++) {
6-
if (str[i] === char) {
7-
count++;
8-
}
2+
let count = 0;
3+
for (let i = 0; i < stringOfCharacters.length; i++) {
4+
if (stringOfCharacters[i] === findCharacter) {
5+
count++;
96
}
10-
return count;
7+
}
8+
return count;
119
}
1210

1311
module.exports = countChar;

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ test("should count multiple occurrences of a character", () => {
3838
expect(count).toEqual(2);
3939
});
4040
// Scenario: No Occurrences
41+
test("should return 0 when the character does not occur in the string", () => {
42+
const str = "No occurrences here";
43+
const char = "z";
44+
const count = countChar(str, char);
45+
expect(count).toEqual(0);
46+
});
47+
// for empty string scenario.
48+
test("should return 0 when the input string is empty", () => {
49+
const str = "";
50+
const char = "a";
51+
const count = countChar(str, char);
52+
expect(count).toEqual(0);
53+
});
54+
//Scenario: for empty find character.
55+
test("should return 0 when the find character is empty", () => {
56+
const str = "empty find character";
57+
const char = "";
58+
const count = countChar(str, char);
59+
expect(count).toEqual(0);
60+
});
61+
// Scenario: counting empty spaces in a string.
62+
test("should return the count of empty spaces in a string", () => {
63+
const str = "The quick brown fox jumps over the lazy dog";
64+
const char = " ";
65+
const count = countChar(str, char);
66+
expect(count).toEqual(8);
67+
});
4168
// Given the input string `str`,
4269
// And a character `char` that does not exist within `str`.
4370
// When the function is called with these inputs,

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,34 @@ const repeatStr = require("./repeat-str");
99
// When the repeatStr function is called with these inputs,
1010
// Then it should return a string that contains the original `str` repeated `count` times.
1111

12-
test("should repeat the string count times", () => {
12+
test("should repeat the string with no spaces 3 times when count is 3", () => {
1313
const str = "hello";
1414
const count = 3;
1515
const repeatedStr = repeatStr(str, count);
1616
expect(repeatedStr).toEqual("hellohellohello");
1717
});
1818

19-
test("should repeat the string count times", () => {
19+
test("should repeat the string with no spaces 3 times when count is 3", () => {
2020
const str = "CYF";
2121
const count = 3;
2222
const repeatedStr = repeatStr(str, count);
2323
expect(repeatedStr).toEqual("CYFCYFCYF");
2424
});
2525

26-
test("should repeat the string count times", () => {
26+
test("should display the string with spaces one times where count is 1", () => {
2727
const str = "Code Your Future";
2828
const count = 1;
2929
const repeatedStr = repeatStr(str, count);
3030
expect(repeatedStr).toEqual("Code Your Future");
3131
});
3232

33-
test("should repeat the string count times", () => {
33+
test("should return empty string when count is 0 times", () => {
3434
const str = "hello";
3535
const count = 0;
3636
const repeatedStr = repeatStr(str, count);
3737
expect(repeatedStr).toEqual("");
3838
});
3939

40-
test("should repeat the string count times", () => {
41-
const str = "ITP";
42-
const count = 5;
43-
const repeatedStr = repeatStr(str, count);
44-
expect(repeatedStr).toEqual("ITPITPITPITPITP");
45-
});
46-
47-
// Case: handle count of 1:
4840
// Given a target string `str` and a `count` equal to 1,
4941
// When the repeatStr function is called with these inputs,
5042
// Then it should return the original `str` without repetition.

0 commit comments

Comments
 (0)