Birmingham | 26-ITP-May | Ogbemi Mene | sprint 3 | 2-practice TDD coursework exercises#1491
Conversation
This comment has been minimized.
This comment has been minimized.
| const pr = new Intl.PluralRules("en-US", { type: "ordinal" }); | ||
| const suffixes = { one: "st", two: "nd", few: "rd", other: "th" }; | ||
| const rule = pr.select(n); | ||
| return `${n}${suffixes[rule]}`; |
There was a problem hiding this comment.
Interesting approach. Could you solve it without using any built-in API?
| test("should append 'th' for all other numbers", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(20)).toEqual("20th"); | ||
| expect(getOrdinalNumber(34)).toEqual("34th"); | ||
| expect(getOrdinalNumber(100)).toEqual("100th"); | ||
| }); |
There was a problem hiding this comment.
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?
To make the test coverage more comprehensive, consider using arrays and loops (or other suitable Jest patterns) to test multiple values, ideally covering numbers that end with every possible digit in this category.
There was a problem hiding this comment.
ok. take a look at the new commit i made if that meets the standard you want
Refactor tests for getOrdinalNumber to include cases for numbers ending in 0, 4, 5, 6, 7, 8, or 9.
…/github.com/meneogbemi42-bit/Module-Structuring-and-Testing-Data into Sprint-3/-Practice-TDD-Coursework-Exercises
| if (n < 0) { | ||
| positiveN = -n; | ||
| } else { | ||
| positiveN = n; | ||
| } |
There was a problem hiding this comment.
-
Indentation is off.
-
Could also just use
Math.abs()
Self checklist
this PR demonstrates understanding of TDD:
Tests are written with explanatory comments, Implementation passes the test cases. Covers edge cases (negative numbers, teens exceptions), Clean, readable code structure.