Manchester| 26-ITP-Jan | Ofonime Edak | Sprint 3 | TDD#1226
Manchester| 26-ITP-Jan | Ofonime Edak | Sprint 3 | TDD#1226Ofonimeedak wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
|
||
| // case 5: expect number not included in the above case to return th | ||
| test("should return 'th' for numbers ending with 4, 5,6,7,8,9,0", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| expect(getOrdinalNumber(6)).toEqual("6th"); | ||
| expect(getOrdinalNumber(7)).toEqual("7th"); | ||
| expect(getOrdinalNumber(8)).toEqual("8th"); | ||
| expect(getOrdinalNumber(9)).toEqual("9th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); |
There was a problem hiding this comment.
Your tests are fine. But there might be one edge case you are missing out on. You handled 11 and 13; is there one more key group you might have missed?
There was a problem hiding this comment.
Yes you caught me I think is 12
| const numStr = num.toString(); | ||
| const numLength = numStr.length; | ||
| if (numStr[numLength - 2] === "1" && numStr[numLength - 1] === "1") { | ||
| return num + "th"; | ||
| } else if (numStr[numLength - 1] === "1") { | ||
| return num + "st"; | ||
| } else if (numStr[numLength - 2] === "1" && numStr[numLength - 1] === "3") { | ||
| return num + "th"; | ||
| } else if (numStr[numLength - 1] === "3") { | ||
| return num + "rd"; | ||
| } else if (numStr[numLength - 1] === "2") { | ||
| return num + "nd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } |
There was a problem hiding this comment.
There is a better arithmetic operator to be used for this function instead of string indexing. This ensures all edge cases are handled in your tests. To ensure code clarity and to avoid string manipulation
There was a problem hiding this comment.
I will have a look at that said operator and how to use it moving forward.
Theoreoluwa
left a comment
There was a problem hiding this comment.
Great job so far Edak. Kindly look at the comments made to improve the work done. Well done!
Self checklist
Changelist
I have implemented all function and test cases using the Jest testing framework
I have run the test using npm run test
Sprint-3 TDD on testing of data using the Jest framework