-
-
Notifications
You must be signed in to change notification settings - Fork 239
London | 25-ITP-September | Alexandru Pocovnicu | Coursework/sprint 3 | 2 practice tdd #776
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
7b93eed
86a4f93
7429d54
a59de40
9af1dec
de7beb8
dd1f125
a2ae864
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,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let char = 0; | ||
| for(let i = 0;i < stringOfCharacters.length;i++){ | ||
| if(stringOfCharacters[i] === findCharacter){ | ||
| char++; | ||
| } | ||
| } | ||
| return char | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,26 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit=Number(num.toString().slice(-1)); | ||
| const lastTwoDigits=Number(num.toString().slice(-2)); | ||
|
Comment on lines
+2
to
+3
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. You correctly do the type check on L5. Should you be extracting lastDigit and lastTwoDigits before you make sure that |
||
|
|
||
| if(typeof num !=="number"){ | ||
| return NaN; | ||
| } | ||
|
|
||
| if(lastTwoDigits>=10 && lastTwoDigits<=13){ | ||
| return `${num}th`; | ||
| } | ||
|
|
||
| if (lastDigit === 1) { | ||
| return `${num}st`; | ||
| } else if (lastDigit === 2) { | ||
| return `${num}nd`; | ||
| } else if (num === 3) { | ||
|
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. Are you sure this is the right condition? Looks like a bug. |
||
| return "3rd"; | ||
| } | ||
|
|
||
| return `${num}th`; | ||
|
|
||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,32 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| test("should return '121st' for 121", () =>{ | ||
|
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 test cases are good but I think there are more edge cases that you could cover to make sure your function behaves in a way you designed. For example, what happens when you pass 0 or 1.5? Also, I think you could have more comprehensive test cases for numbers. With the current bug you have |
||
| expect(getOrdinalNumber(121)).toEqual("121st") | ||
| }) | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| test("should return '5th' for 5", () => { | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| }); | ||
|
|
||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
|
|
||
| test("should return '-11th' for -11", () => { | ||
| expect(getOrdinalNumber(-11)).toEqual("-11th"); | ||
| }); | ||
|
|
||
| test("should return NaN for s", () => { | ||
| expect(getOrdinalNumber("8")).toEqual(NaN); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str,count) { | ||
| if(count<0){ | ||
| return "Error: negative numbers are not valid"; | ||
| } | ||
| return (str.repeat(count)); | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,12 +21,33 @@ test("should repeat the string count times", () => { | |
| // 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 not repeat the string", ()=>{ | ||
|
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 above, these test cases are good but they are a bit slim. You could add couple of more tests to test different variations of count and try to break your function by adding some tests for edge cases, like in the case you pass str="". |
||
| 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", ()=>{ | ||
| 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 return error", ()=>{ | ||
| const str="hello"; | ||
| const count=-1; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("Error: negative numbers 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.
This test case is good but can you think of other test cases? For example, what happens in the following cases:
and etc. I think there are a few test cases to consider, as str and char can vary in length, type and content. This will show you if you have protected against various edge cases your function.