-
-
Notifications
You must be signed in to change notification settings - Fork 394
London | 26-ITP-May |Rizqah Popoola | Sprint 3 | practice tdd #1498
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,5 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| return stringOfCharacters.split(findCharacter).length-1 | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,34 @@ test("should count multiple occurrences of a character", () => { | |
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| }); | ||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "pneumonoultramicroscopicsilicovolcanoconoisis"; | ||
| const char = "o"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(9); | ||
| }); | ||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "pneumonoultramicroscopicsilicovolcanoconoisis"; | ||
| const char = "i"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(6); | ||
| }); | ||
|
|
||
|
|
||
| // 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 count multiple occurrences of a character", () => { | ||
|
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. Do these test descriptions match what is being tested? |
||
| const str = "interesting"; | ||
| const char = "b"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| test("should count multiple occurrences of a character", () => { | ||
|
Comment on lines
+38
to
+44
Contributor
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. If these tests are testing different behavior, they should have a different description. Also, do look up
|
||
| const str = "future"; | ||
| const char = "m"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if ([11, 12, 13].includes(num % 100)){ | ||
| return num + "th" | ||
| } | ||
| if (String(num).at(-1)=== "1"){ | ||
| return num + "st" | ||
| } | ||
| if (String(num).at(-1) === "2"){ | ||
| return num + "nd" | ||
| } | ||
| if (String(num).at(-1) === "3"){ | ||
| return num + "rd" | ||
| } | ||
| else{ | ||
| return num + "th" | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,30 @@ 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(131)).toEqual("131st"); | ||
| expect(getOrdinalNumber(1021)).toEqual("1021st"); | ||
| }); | ||
| //case 2; Numbers ending with 4,5,6,7,8,9 and 0 | ||
| test("should append 'th' for numbers ending with 4,5,6,7,8,9,0", () => { | ||
| expect(getOrdinalNumber(104)).toEqual("104th"); | ||
| expect(getOrdinalNumber(2000)).toEqual("2000th"); | ||
| expect(getOrdinalNumber(167)).toEqual("167th"); | ||
| expect(getOrdinalNumber(19)).toEqual("19th"); | ||
|
Comment on lines
+24
to
+27
Contributor
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. To make the test coverage more comprehensive, consider using arrays and loops (or other suitable Jest patterns) to test multiple values, ideally covering numbers that end with every possible digit in this category. |
||
| }); | ||
| //case 3; Numbers ending with 11,12,13 | ||
| test("should append 'th' for numbers ending with 11,12,13", () => { | ||
| expect(getOrdinalNumber(1013313)).toEqual("1013313th"); | ||
| expect(getOrdinalNumber(2012)).toEqual("2012th"); | ||
| expect(getOrdinalNumber(16711)).toEqual("16711th"); | ||
| }); | ||
| //case 4;Numbers ending with 2 | ||
| test("should append 'nd' for numbers ending with 2", () => { | ||
| expect(getOrdinalNumber(102)).toEqual("102nd"); | ||
| expect(getOrdinalNumber(2022)).toEqual("2022nd"); | ||
| expect(getOrdinalNumber(16732)).toEqual("16732nd"); | ||
| }); | ||
| //case 4;Numbers ending with 3 | ||
| test("should append 'nd' for numbers ending with 3", () => { | ||
|
Comment on lines
+36
to
+42
Contributor
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. Better to clarify these scenarios do not include numbers ending with 12 and 13. |
||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(2023)).toEqual("2023rd"); | ||
| expect(getOrdinalNumber(16733)).toEqual("16733rd"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| function repeatStr() { | ||
| function repeatStr(str, count) { | ||
| // 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"; | ||
| if(count >= 0){ | ||
| return str.repeat(count); | ||
|
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. Can you re-read the task description and make sure you have done everything? |
||
| } | ||
|
Comment on lines
2
to
+6
Contributor
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 missed the comment on line 2. |
||
| else{ | ||
| throw new Error("Invalid count"); | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeatStr; | ||
|
Contributor
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. Having identical test descriptions in all tests would make TDD difficult. Could you make the test descriptions more informative and distinctive? Perhaps also group similar tests into the same test category? |
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.
The test descriptions suggest that these tests belong to the same category. If they are testing the same behavior with different input values, consider grouping them into a single test suite.
Also, the string
"pneumonoultramicroscopicsilicovolcanoconoisis"is long and difficult to read, making it hard for someone reviewing the test to verify that there are actually nine o's or six i's.