London | 26-ITP-May | Hugh Mills | Sprint 3 | 2. practice tdd - #1607
London | 26-ITP-May | Hugh Mills | Sprint 3 | 2. practice tdd#1607HM-127BTY wants to merge 2 commits into
Conversation
put in code using "if" function.
Making of code and tests
There was a problem hiding this comment.
semicolon missing in line 8 and line 11.
fun fact: In the original design of JavaScript, there was no semicolon, but it has been added later on - so that nowadays JS programmers generally follow the practice of adding semicolon.
| test("should count multiple occurrences of a character", () => { | ||
| const str = "aaa aa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character with random characters", () => { | ||
| const str = "ajhyabhaakaka"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(6); | ||
| }) | ||
|
|
There was a problem hiding this comment.
The two cases looks quite similar, they both have random characters in the middle of str, and they both start with char, and they both end with char.
| // 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. | ||
| test("should return 0 with no occurrence of the character", () => { | ||
| const str ="abcd"; | ||
| const char = "e"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); |
There was a problem hiding this comment.
There should be one more boundary case making char has no occurrence in str. Can you think of that special case?
There was a problem hiding this comment.
I think the question requires to also handle 2nd and 3rd etc. Since the question itself may not be quite clear about that, you may clarify in slack channel. Thanks.
There was a problem hiding this comment.
if the question requires to also handle 2nd and 3rd etc, then there will be more test cases.
Learners, PR Template
Self checklist
Changelist
Added testing and code, starting with writing a test before adding code.