-
-
Couldn't load subscription status.
- Fork 240
Glasgow | 25-ITP-SEP | Alaa Tagi | Sprint 3 | Coursework/sprint 3 practice tdd #758
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 20 commits
b5de08b
b5fa562
3898643
78d374a
d07dd99
a223e45
ef42f92
b02a77f
3f11ed4
d7507ff
2eaa92c
73c8fcf
52660c9
408f2e1
1f0b098
d276533
ce08a1f
874c5ca
ea944a1
d25945b
5e24460
d269acc
62bf3a9
6f9d56b
b1c0345
8ff02d3
2aafdb6
c491953
0f0c704
9e74422
099a76f
2db8252
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,9 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| } | ||
| return stringOfCharacters.split(findCharacter).length - 1; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| console.log(countChar('hello', 'l')); | ||
| console.log(countChar('hello', 'z')); | ||
| console.log(countChar('alaaaaa', 'a')); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| const countChar = require("./count"); | ||
| // Given a string str and a single character char to search for, | ||
| // When the countChar function is called with these inputs, | ||
| // Then it should: | ||
| // Then it should: correctly count the occurrences of char in str. | ||
|
|
||
|
|
||
| // Scenario: Multiple Occurrences | ||
| // Given the input string str, | ||
|
|
@@ -17,8 +18,16 @@ test("should count multiple occurrences of a character", () => { | |
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
|
|
||
| // Scenario: No Occurrences | ||
| // Given the input string str, | ||
| // And a character char that does not exist within the case-sensitive str, | ||
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. | ||
|
|
||
| test("should return 0 for 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. This test is good but it doesn't test different possible function inputs. What if the inputs' types are not strings, the |
||
| const str = "hello"; | ||
| const char = "z"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,23 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| num = num.toString(); | ||
| if (num.slice(-2) === '11' || num.slice(-2) === '12' || num.slice(-2) === '13') { | ||
|
||
| return num + 'th'; | ||
| } else if (num.slice(-1) === '1') { | ||
| return num + 'st'; | ||
| } else if (num.slice(-1) === '2') { | ||
| return num + 'nd'; | ||
| } else if (num.slice(-1) === '3') { | ||
| return num + 'rd'; | ||
| } else { | ||
| return num + 'th'; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| console.log(getOrdinalNumber(1)); | ||
| console.log(getOrdinalNumber(2)); | ||
| console.log(getOrdinalNumber(3)); | ||
| console.log(getOrdinalNumber(4)); | ||
| console.log(getOrdinalNumber(11)); | ||
| console.log(getOrdinalNumber(22)); | ||
| console.log(getOrdinalNumber(33)); | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,50 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
|
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. I like these test cases but again, what are other expected/unexpected inputs your function can receive and how will it behave? For example, what if num is undefined, a boolean, etc.? That's just two examples of num being not of a type you expect. |
||
| // Case 2: Identify the ordinal number for 2 | ||
| // When the number is 2, | ||
| // Then the function should return "2nd" | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| // Case 3: Identify the ordinal number for 3 | ||
| // When the number is 3, | ||
| // Then the function should return "3rd" | ||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| // Case 4: Identify the ordinal number for 4 | ||
| // When the number is 4, | ||
| // Then the function should return "4th" | ||
|
|
||
| test("should return '4th' for 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| }); | ||
|
|
||
| // Case 5: Identify the ordinal number for 11 | ||
| // When the number is 11, | ||
| // Then the function should return "11th" | ||
|
|
||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
|
|
||
| // Case 6: Identify the ordinal number for 22 | ||
| // When the number is 22, | ||
| // Then the function should return "22nd" | ||
|
|
||
| test("should return '22nd' for 22", () => { | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| }); | ||
| // Case 7: Identify the ordinal number for 33 | ||
| // When the number is 33, | ||
| // Then the function should return "33rd" | ||
|
|
||
| test("should return '33rd' for 33", () => { | ||
| expect(getOrdinalNumber(33)).toEqual("33rd"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| const str = arguments[0]; | ||
| const count = arguments[1]; | ||
|
||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
| module.exports = repeat; | ||
| console.log(repeat("hello", 3)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| const repeat = require("./repeat"); | ||
| // Given a target string str and a positive integer count, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should: | ||
| // Then it should: repeat the str count times and return a new string containing the repeated str values. | ||
|
|
||
| // case: repeat String: | ||
| // Given a target string str and a positive integer count, | ||
|
|
@@ -11,22 +11,39 @@ const repeat = require("./repeat"); | |
|
|
||
| test("should repeat the string count times", () => { | ||
| const str = "hello"; | ||
| const count = 3; | ||
| const count = 4; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("hellohellohello"); | ||
| expect(repeatedStr).toEqual("hellohellohellohello"); | ||
| }); | ||
|
|
||
| // case: handle Count of 1: | ||
| // Given a target string str and a count equal to 1, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. | ||
|
|
||
| test("should return the original string when count is 1", () => { | ||
|
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. This test suit are more comprehensive but can you think of other test cases? 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. Hi @jennethydyrova i have fixed all the errors that you have mentioned to me. 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. Have you tried running the tests you wrote? 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 you try to run your unit tests, you will see that some of them are failing both for this function and getOrdinalNumber. Can you try to fix tests/functions by reading output produced when you run tests? 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. Yes, I have and it passed all the tests. 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. The unit tests in your screenshots do not match those in the PR. Take a look at and on the screenshot you sent the last test is 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. @jennethydyrova, 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. Please always double check if you pushed your local changes, deleted all scratch work (including console logs) and ran all unit tests before requesting another round of review. It will reduce time I spend on reviewing your code and you going back to the same PR over and over again. File changes tab is quite useful for checking if you code is up to standard. I don't see any new changes. I assume you made some local changes but you haven't pushed them. 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. @jennethydyrova, I am sorry and I appreciate your time. But I am so confused too I make the changes, do push as usual and in here every thing appears.
Like this pic here it shows that the changes has been push and I do not see any unstage files. Thanks for you patient with me 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. No worries. Okay, I can see these changes and I can see from the function implementation, that this particular unit test on the screenshot you sent will fail but you can understand this by just running unit tests. You have these changes locally, right? If you have same changes locally and you run unit tests, some of them will fail in |
||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
| // case: Handle Count of 0: | ||
| // Given a target string str and a count equal to 0, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should return an empty string, ensuring that a count of 0 results in an empty output. | ||
|
|
||
| test("should return an empty string when count is 0", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
| // case: Negative Count: | ||
| // Given a target string str and a negative integer count, | ||
| // When the repeat function is called with these inputs, | ||
| // Then it should throw an error or return an appropriate error message, as negative counts are not valid. | ||
| // Then it should throw an error or return an appropriate error message,as negative counts are not valid. | ||
| test("should throw an error when count is negative", () => { | ||
| const str = "hello"; | ||
| const count = -2; | ||
| expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer"); | ||
| }); | ||

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.
Let's keep the PR clean and focused. Could you please remove all console logs from your PR?