-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP-May | Dagim Daniel | Sprint 3 | Practice-tdd #1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,54 @@ test("should count multiple occurrences of a character", () => { | |
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "Code your Future"; | ||
| const char = "u"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(3); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "Introduction to Programming"; | ||
| const char = "o"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(4); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "Introduction to Javascript"; | ||
| const char = "i"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(2); | ||
| }); | ||
| // Scenario: No Occurrences | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have the setup comments for a 'No Occurrences' scenario, but the test block is missing. maybe you've forgotten to write this one? |
||
| test("should return 0 when the character does not occur in the string", () => { | ||
| const str = "No occurrences here"; | ||
| const char = "z"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| // for empty string scenario. | ||
| test("should return 0 when the input string is empty", () => { | ||
| const str = ""; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| //Scenario: for empty find character. | ||
| test("should return 0 when the find character is empty", () => { | ||
| const str = "empty find character"; | ||
| const char = ""; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| // Scenario: counting empty spaces in a string. | ||
| test("should return the count of empty spaces in a string", () => { | ||
| const str = "The quick brown fox jumps over the lazy dog"; | ||
| const char = " "; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(8); | ||
| }); | ||
| // Given the input string `str`, | ||
| // And a character `char` that does not exist within `str`. | ||
| // When the function is called with these inputs, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const s = ["th", "st", "nd", "rd"]; | ||
| const lastDigits = num % 100; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job on the logic
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i do install the prettier extension, just failed to make it auto-format on save. thanks i will fix it. |
||
| // Uses the index 1, 2, or 3 for st/nd/rd, defaults to 0 (th) | ||
| return num + (s[(lastDigits - 20) % 10] || s[lastDigits] || s[0]); | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| function repeatStr() { | ||
| // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). | ||
| // The goal is to re-implement that function, not to use it. | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imagine one of these tests fails and you're reading that red output in the console. Since all the descriptions are identical right now (both here and in count.test.js), how could we update the test names to be more self-explanatory so you immediately know exactly what broke?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right this could be fix, maybe by making clear test description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job on these tests!
Since you are already thinking about edge cases like that, what are some other tricky inputs we might want to test for? (For example: what happens if someone passes in an empty string, or wants to count empty spaces?