-
-
Notifications
You must be signed in to change notification settings - Fork 337
Manchester | 26-ITP-JAN | Abdu Mussa | Sprint 3 | 2-practice-tdd-complete #1174
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
Open
Abduhasen
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
Abduhasen:coursework/sprint-3-practice-tdd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| function getOrdinalNumber(number) { | ||
| const lastTwoDigits = number % 100; | ||
| if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) { | ||
| return number + "th"; | ||
| } | ||
| const lastDigit = number % 10; | ||
| let suffix; | ||
| if (lastDigit === 1) { | ||
| suffix = "st"; | ||
| } else if (lastDigit === 2) { | ||
| suffix = "nd"; | ||
| } else if (lastDigit === 3) { | ||
| suffix = "rd"; | ||
| } else { | ||
| suffix = "th"; | ||
| } | ||
|
|
||
| return number + suffix; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(word, times) { | ||
| if (times > 0) { | ||
| return word.repeat(times); | ||
| } else if (times < 0) { | ||
| return "Error:negative number not allowed"; | ||
| } else { | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeatStr; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,24 +9,40 @@ const repeatStr = require("./repeat-str"); | |
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return a string that contains the original `str` repeated `count` times. | ||
|
|
||
| test("should repeat the string count times", () => { | ||
| const str = "hello"; | ||
| const count = 3; | ||
| const repeatedStr = repeatStr(str, count); | ||
| test("should return the string the given number of count when count is a positive number", () => { | ||
| let word = "hello"; | ||
| let times = 3; | ||
| const repeatedStr = repeatStr(word, times); | ||
| expect(repeatedStr).toEqual("hellohellohello"); | ||
| }); | ||
|
|
||
| // Case: handle count of 1: | ||
| // Given a target string `str` and a `count` equal to 1, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return the original `str` without repetition. | ||
|
|
||
| test("should return the original string without repetition when count is 1", () => { | ||
| let word = "code your future"; | ||
| let times = 1; | ||
| const repeatedStr = repeatStr(word, times); | ||
| expect(repeatedStr).toEqual("code your future"); | ||
| }); | ||
| // Case: Handle count of 0: | ||
| // Given a target string `str` and a `count` equal to 0, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return an empty string. | ||
|
|
||
| test("should return an empty string when the number of times is 0", () => { | ||
| let word = "hello"; | ||
| let times = 0; | ||
| const repeatedStr = repeatStr(word, times); | ||
| expect(repeatedStr).toBe(""); | ||
| }); | ||
| // Case: Handle negative count: | ||
| // Given a target string `str` and a negative integer `count`, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should throw an error, as negative counts are not valid. | ||
| test("should return a string 'negative number not allowed' when negative number passed", () => { | ||
|
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. Should also update the test description as well.
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. It is fixed now thank you very much for the feed backs |
||
| let word = "hello"; | ||
| let times = -3; | ||
| const repeatedStr = repeatStr(word, times); | ||
| expect(repeatedStr).toBe("Error:negative number not allowed"); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I overlooked this in my previous review.
When a function that is expected to return a string is designed to return a string on error,
how should the caller distinguish the return value of these two function calls?
repeatStr("Error:negative number not allowed", 1)repeatStr("Hello World", -1)They both return the same value.
The requirement is "to throw an error when count is negative". Can you update this implementation and the Jest test accordingly?
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.
I changed the function and implemented jest test case for negative numbers.