Repository navigation
Manchester | 26-ITP-Sept | Rahana Suleiman | Sprint 2 | Practice TDD #1691
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
807193d
c2932ad
f50e119
677d31c
7b24557
8281fdd
a1f5c71
6d9611c
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,3 +1,8 @@ | ||
| export function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (const char of stringOfCharacters) { | ||
| if (char === findCharacter) | ||
| count ++ | ||
| } | ||
| return count; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| export function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastTwoDigits = num % 100; | ||
| const lastDigit = num % 10; | ||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return `${num}th`; | ||
| } | ||
| if (lastDigit === 1) { | ||
| return `${num}st`; | ||
| } | ||
| if (lastDigit === 2) { | ||
| return `${num}nd`; | ||
| } | ||
| if (lastDigit === 3) { | ||
| return `${num}rd`; | ||
| } | ||
|
|
||
| return `${num}th`; | ||
| } |
|
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. Good coverage of test cases. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,39 @@ | ||
| import { getOrdinalNumber } from "./get-ordinal-number.js"; | ||
| // In this week's prep, we started implementing getOrdinalNumber. | ||
|
|
||
| // Continue testing and implementing getOrdinalNumber for additional cases. | ||
| // Write your tests using Jest — remember to run your tests often for continual feedback. | ||
|
|
||
| // To ensure thorough testing, we need broad scenarios that cover all possible cases. | ||
| // Listing individual values, however, can quickly lead to an unmanageable number of test cases. | ||
| // Instead of writing tests for individual numbers, consider grouping all possible input values | ||
| // into meaningful categories. Then, select representative samples from each category to test. | ||
| // This approach improves coverage and makes our tests easier to maintain. | ||
|
|
||
| // 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. | ||
| // Case 1: Numbers ending with 1 (except 11) | ||
| test("should append 'st' for numbers ending with 1, except those ending with 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(131)).toEqual("131st"); | ||
| }); | ||
|
|
||
| // Case 2: Numbers ending with 2 (except 12) | ||
| test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(102)).toEqual("102nd"); | ||
| }); | ||
|
|
||
| // Case 3: Numbers ending with 3 (except 13) | ||
| test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(103)).toEqual("103rd"); | ||
| }); | ||
|
|
||
| // Case 4: Teen numbers (11, 12, 13) and numbers ending in them | ||
| test("should append 'th' for teen numbers 11, 12, 13 and their multiples", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| expect(getOrdinalNumber(111)).toEqual("111th"); | ||
| expect(getOrdinalNumber(112)).toEqual("112th"); | ||
| expect(getOrdinalNumber(113)).toEqual("113th"); | ||
| }); | ||
|
|
||
| // Case 5: All other digits (0, 4, 5, 6, 7, 8, 9) | ||
| test("should append 'th' for all other numbers", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(105)).toEqual("105th"); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| export function repeatStr() { | ||
| export function repeatStr(str, count) { | ||
| // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). | ||
| // The goal is to re-implement that function, not to use it. | ||
| return "hellohellohello"; | ||
| if (count < 0) { | ||
| throw new RangeError("Count must be a non-negative integer"); | ||
| } | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } |
|
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. Your test cases are correct. Just for you to think a little bit more, besides |
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.
There is a special
strthat would give 0 anyway. Please add that test case as well. Thank you.