-
-
Notifications
You must be signed in to change notification settings - Fork 337
Birmingham | 26-ITP-JAN | Merve Reis | Sprint 3 | Practice TDD #1124
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
9d13824
0280acb
6da58b9
388b82e
980550f
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,13 @@ | ||
| 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,20 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit = num % 10; | ||
| const lastTwoDigits = num % 100; | ||
|
|
||
| if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| if (lastDigit === 1) { | ||
| return num + "st"; | ||
| } else if (lastDigit === 2) { | ||
| return num + "nd"; | ||
| } else if (lastDigit === 3) { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,35 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| // Case 1: Numbers ending with 1 (but not 11) | ||
| // When the number ends with 1, except those ending with 11, | ||
| // Then the function should return a string by appending "st" to the number. | ||
| test("should append 'st' for numbers ending with 1, except those ending with 11", () => { | ||
| test("should append 'st' for numbers ending with 1, except 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(131)).toEqual("131st"); | ||
| expect(getOrdinalNumber(31)).toEqual("31st"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| }); | ||
|
|
||
| test("should append 'nd' for numbers ending with 2, except 12", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(82)).toEqual("82nd"); | ||
| }); | ||
|
|
||
| test("should append 'rd' for numbers ending with 3, except 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(33)).toEqual("33rd"); | ||
| expect(getOrdinalNumber(93)).toEqual("93rd"); | ||
| }); | ||
|
|
||
| test("should append 'th' for the exceptions 11, 12, and 13", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| expect(getOrdinalNumber(111)).toEqual("111th"); | ||
| }); | ||
|
|
||
| test("should append 'th' for all other numbers", () => { | ||
|
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. When a test fails with the message "... all other numbers", it may be unclear what "other numbers" actually refers to. Can you revise the test description to make it more informative?
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. @cjyuan I changed the test title to more informative way, now I specified the exact numbers |
||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(35)).toEqual("35th"); | ||
| expect(getOrdinalNumber(99)).toEqual("99th"); | ||
| expect(getOrdinalNumber(100)).toEqual("100th"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (typeof count !== "number" || count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
|
|
||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
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 more samples.
Could consider testing these cases:
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.
@cjyuan I added more test cases