-
-
Notifications
You must be signed in to change notification settings - Fork 337
London | 26-ITP-Jan | Johnny Vargas | Sprint 3 | Practice TDD #1212
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,10 @@ | ||
| 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 |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit = num % 10; | ||
| const lastTwoDigits = num % 100; | ||
| if (lastDigit === 1 && lastTwoDigits !== 11) { | ||
| return num + "st"; | ||
| } | ||
| else if (lastDigit === 2 && lastTwoDigits !== 12) { | ||
| return num + "nd"; | ||
| } | ||
| else if (lastDigit === 3 && lastTwoDigits !== 13) { | ||
| return num + "rd" | ||
| } | ||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
|
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. The test categories in this script do not yet cover all possible numbers. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Negative counts are not allowed.") | ||
| } | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,30 @@ test("should repeat the string count times", () => { | |
| // 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 print the string once", () => { | ||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
|
|
||
| // 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 print nothing", () => { | ||
|
Comment on lines
+23
to
+34
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.
A common format is: Can you also include the "condition" part into these descriptions? |
||
| const str = ""; | ||
| const count = 0; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
|
|
||
| // 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 error if using negatives", () => { | ||
| const str = "hello"; | ||
| const count = -5; | ||
| expect(() => repeatStr(str, count)).toThrow(); | ||
| }); | ||
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.
Could consider testing a few more samples in this script - higher chance to detect bugs in code.
The original specification did not clearly state whether the character match should be case-sensitive.
Most people would probably assume that it is, but to demonstrate our understanding or clarify the assumption we made,
we could add test cases to convey this. For examples,