generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 272
Birmingham | 25-ITP-Sep | Hadi-Vahidi| Sprint 3 |Coursework/sprint-3-practice-tdd #830
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
Open
HadiVahidi20
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
HadiVahidi20:coursework/sprint-3-practice-tdd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1189fcd
Add age calculation functionality and HTML structure for age input
HadiVahidi20 78b6a33
Refactor age calculator layout and improve form structure
HadiVahidi20 ea977e5
addWnetListener Example added
HadiVahidi20 22c0fee
Refactor age calculator layout and improve form structure
HadiVahidi20 c346f52
percentage exersice added
HadiVahidi20 ea0fca9
Enhance percentage exercise layout and add area calculation functiona…
HadiVahidi20 15f6b6b
Implement countChar function and tests
HadiVahidi20 a135b88
Implement countChar function and tests
HadiVahidi20 0036b8d
the get-ordinal-number test is done
HadiVahidi20 70bf4d4
Merge branch 'CodeYourFuture:main' into main
HadiVahidi20 8d5db28
Merge branch 'main' into coursework/sprint-3-practice-tdd
HadiVahidi20 1413394
refactor: throw error for negative count in repeat() to avoid ambiguo…
HadiVahidi20 a57813f
Improve variable names and test coverage for getOrdinalNumber
HadiVahidi20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,15 @@ | ||
| function getOrdinalNumber(num) { | ||
| const itsTwoLastDigs = num % 100; | ||
| if (itsTwoLastDigs === 11 || itsTwoLastDigs === 12 || itsTwoLastDigs === 13) { | ||
| const numberLastTwoDigits = num % 100; | ||
|
|
||
| if (numberLastTwoDigits === 11 || numberLastTwoDigits === 12 || numberLastTwoDigits === 13) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| const lastDig = num % 10; | ||
| if (lastDig === 1) return num + "st"; | ||
| if (lastDig === 2) return num + "nd"; | ||
| if (lastDig === 3) return num + "rd"; | ||
| const numberLastDigit = num % 10; | ||
| if (numberLastDigit === 1) return num + "st"; | ||
| if (numberLastDigit === 2) return num + "nd"; | ||
| if (numberLastDigit === 3) return num + "rd"; | ||
| return num + "th"; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| module.exports = getOrdinalNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,42 @@ | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
| // 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 | ||
|
|
||
| // Case 1: Identify the ordinal number for 1 | ||
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
|
|
||
| describe("getOrdinalNumber", () => { | ||
| test("append 'st' to numbers ending in 1 expect 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| test("returns 'st', 'nd', 'rd', 'th' for standard numbers", () => { | ||
| expect(getOrdinalNumber(1)).toBe("1st"); | ||
| expect(getOrdinalNumber(2)).toBe("2nd"); | ||
| expect(getOrdinalNumber(3)).toBe("3rd"); | ||
| expect(getOrdinalNumber(4)).toBe("4th"); | ||
| expect(getOrdinalNumber(10)).toBe("10th"); | ||
| }); | ||
|
|
||
| test("append 'rd' to numbers ending in 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(33)).toEqual("33rd"); | ||
| expect(getOrdinalNumber(103)).toEqual("103rd"); | ||
| test("handles numbers ending with 11, 12, 13 as special cases", () => { | ||
| expect(getOrdinalNumber(11)).toBe("11th"); | ||
| expect(getOrdinalNumber(12)).toBe("12th"); | ||
| expect(getOrdinalNumber(13)).toBe("13th"); | ||
| expect(getOrdinalNumber(111)).toBe("111th"); | ||
| expect(getOrdinalNumber(112)).toBe("112th"); | ||
| expect(getOrdinalNumber(113)).toBe("113th"); | ||
| }); | ||
| test("should return '4th' for 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
|
|
||
| test("handles numbers ending with 1, 2, or 3 correctly beyond 100", () => { | ||
| expect(getOrdinalNumber(101)).toBe("101st"); | ||
| expect(getOrdinalNumber(102)).toBe("102nd"); | ||
| expect(getOrdinalNumber(103)).toBe("103rd"); | ||
| expect(getOrdinalNumber(104)).toBe("104th"); | ||
| expect(getOrdinalNumber(132)).toBe("132nd"); | ||
| }); | ||
|
|
||
| test("should return '12th' for 12", () => { | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| test("returns '0th' for zero", () => { | ||
| expect(getOrdinalNumber(0)).toBe("0th"); | ||
| }); | ||
| test("should return '13th' for 13", () => { | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
|
|
||
| test("works with large numbers", () => { | ||
| expect(getOrdinalNumber(1001)).toBe("1001st"); | ||
| expect(getOrdinalNumber(1012)).toBe("1012th"); | ||
| }); | ||
|
|
||
| test("append 'nd' to numbers ending in 2, except those ending in 12", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(132)).toEqual("132nd"); | ||
| test("handles negative numbers", () => { | ||
| expect(getOrdinalNumber(-1)).toBe("-1st"); | ||
| expect(getOrdinalNumber(-11)).toBe("-11th"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Did you prepare this test because the function is supposed to behave like that, or because your function is behaving like that?