-
-
Notifications
You must be signed in to change notification settings - Fork 260
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 3 | 2 Practice TDD #798
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
Changes from 6 commits
2c2b0f3
6db0981
7362e86
1f72b49
ed1a393
93d9cb6
9bc1c34
01cb978
86311c7
bd7847f
1c66099
03b238e
14306cc
a6bbe86
aaa3da4
4548cb5
4027919
2b82934
4153632
2957d4b
95ba4bf
d0b6378
3243748
adb9421
f6115be
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,6 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| const characterOccurrence = stringOfCharacters.split(findCharacter).length - 1; | ||
| return characterOccurrence; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function getOrdinalNumber(num) { | ||
|
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. Unfortunately, this function is not passing the acceptance criteria. Please try to pass different values to the function and see if it returns what you expect. |
||
| return "1st"; | ||
| if (num === 1 || num === 21) { | ||
| return `${num}st`; | ||
| } else if (num === 11) { | ||
| return `${num}th`; | ||
| } else if (num === 2) { | ||
| return `${num}nd`; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,15 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| test("should return '11th' for 11", () => { | ||
|
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. Same as a previous comment regarding very slim test suite. Try to think of more test cases. |
||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }) | ||
|
|
||
| test("should return '21st' for 21", () => { | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| }) | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(valueToRepeat, numOfTimes) { | ||
| let repeatedValue = ""; | ||
| if (numOfTimes > 0) { | ||
| for (let i = 0; i < numOfTimes; i++) { | ||
| repeatedValue += valueToRepeat; | ||
| } | ||
| } else if (numOfTimes === 0) { | ||
| repeatedValue = ""; | ||
| } | ||
| else { | ||
| repeatedValue = "Negative number invalid"; | ||
| } | ||
| return repeatedValue; | ||
| } | ||
|
|
||
| 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 return the original input with no repetition", () => { | ||
|
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. These unit tests are good, great job on writing them! Now I would like you to think of more test cases, where the values passed to the function are not what you expected. What if you pass integer 3 as |
||
| const str = "milk"; | ||
| const count = 1; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual(str); | ||
| }) | ||
|
|
||
| // 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", () => { | ||
| const str = "rice"; | ||
| 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 return an error message", () => { | ||
| const str = "food"; | ||
| const count = -2; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("Negative number invalid"); | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
This is a good start but this is would not be considered as a good test suite as it covers just one behavior. Good test suite should cover different scenarios based on what type of arguments you pass to the function.