Skip to content

Commit e7cad87

Browse files
committed
count.test.js passed all the tests
1 parent e145d3c commit e7cad87

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
for (let char of stringOfCharacters) {
4+
if (char === findCharacter) count++;
5+
}
6+
return count;
37
}
48

5-
module.exports = countChar;
6-
7-
const countChar = require('../countChar');
8-
9-
describe('countChar()', () => {
10-
test('always returns 5', () => {
11-
expect(countChar('anything', 'a')).toBe(5);
12-
});
13-
14-
test('still returns 5 with empty string', () => {
15-
expect(countChar('', 'z')).toBe(5);
16-
});
17-
18-
test('still returns 5 with special characters', () => {
19-
expect(countChar('!!!', '!')).toBe(5);
20-
});
21-
});
22-
//this is the end.
23-
// Last line
9+
module.exports = countChar;

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
// implement a function countChar that counts the number of times a character occurs in a string
2-
const countChar = require("./count");
3-
4-
function countChar(stringOfCharacters, findCharacter) {
5-
let count = 0;
6-
for (let char of stringOfCharacters) {
7-
if (char === findCharacter) count++;
8-
}
9-
return count;
10-
}
11-
12-
module.exports = countChar;
132

143
// Given a string str and a single character char to search for,
154
// When the countChar function is called with these inputs,
@@ -20,6 +9,9 @@ module.exports = countChar;
209
// And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'),
2110
// When the function is called with these inputs,
2211
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa').
12+
13+
const countChar = require('./count');
14+
2315

2416
test("should count multiple occurrences of a character", () => {
2517
const str = "aaaaa";
@@ -54,7 +46,7 @@ test("should return 0 when the input string is empty", () => {
5446
// Scenario: Special Characters
5547
// It should correctly count spaces and punctuation.
5648
test("should count special characters like spaces or punctuation", () => {
57-
expect(countChar("a b a b", " ")).toEqual(2);
49+
expect(countChar("a b a b", " ")).toEqual(3);
5850
expect(countChar("wow!!!", "!")).toEqual(3);
5951
});
6052

0 commit comments

Comments
 (0)