-
-
Notifications
You must be signed in to change notification settings - Fork 241
Glasgow | 25-ITP-SEP | Mohammed Abdoon | Sprint 3 | Coursework/2-practice-tdd #746
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 3 commits
1e5cad7
a42937d
9600443
c0d9240
f6314c3
ad2180d
94348cb
b46e59d
f55b3a2
f06c4f9
25b1868
06a987e
4b42131
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,10 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let output = 0; | ||
| for( let i=0; i <= stringOfCharacters.length; i++ ) { | ||
| if(stringOfCharacters[i] === findCharacter) | ||
| output++; | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if(num === 1) | ||
| return "1st"; | ||
| return 0; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if(count < 0) { | ||
| return "Error: Negative counts are not valid."; | ||
| } | ||
|
||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,31 @@ test("should repeat the string count times", () => { | |
| // 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 repeat the string only 1 time (no repetition)", () => { | ||
| 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 repeat the string 0 times ( means the output will be an empty string)", () => { | ||
| 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. | ||
| test("should repeat the string 0 times ( means the output will be an empty string)", () => { | ||
| const str = "hello"; | ||
| const count = -3; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("Error: Negative counts are not valid."); | ||
| }); | ||
|
||
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 function should work for any positive integers.
Can you lookup the rules for representing ordinal numbers?
You should prepare tests in
get-ordinal-number.test.jsfile first before implementinggetOrdinalNumber().For example, we can prepare a test for numbers 2, 22, 132, etc. as
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.
Thank you for the feedback. I set the tests for the function and modified the function getOrdinalNumber() to meet the requirements and to handle all possible cases.