generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 269
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | coursework/sprint-3-practice-tdd #880
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
MohammedNaru
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
MohammedNaru: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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
951157c
Add test case for character not found in string count.test.js
MohammedNaru f774e8d
Implement character counting logic in countChar function
MohammedNaru 150a497
Implement getOrdinalNumber function to return correct ordinal suffixes
MohammedNaru 9722cde
Refactor repeatStr function to handle negative counts and return repe…
MohammedNaru 0e92f62
Refactor tests in getOrdinalNumber to streamline cases and improve cl…
MohammedNaru 60864d0
Refactor tests in getOrdinalNumber to cover additional cases and impr…
MohammedNaru 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
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,5 +1,14 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
|
|
||
| for (let char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
|
|
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
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,5 +1,17 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastDigit = num % 10; | ||
| const lastTwoDigits = num % 100; | ||
|
|
||
| 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`; | ||
| } | ||
|
|
||
| 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,13 +1,57 @@ | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
| // In this week's prep, we started implementing getOrdinalNumber | ||
| // Case 2: Identify the ordinal number for 2 | ||
| // When the number is 2, | ||
| // Then the function should return "2nd" | ||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| // Case 3: Identify the ordinal number for 3 | ||
| // When the number is 3, | ||
| // Then the function should return "3rd" | ||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| // Case 4: Identify ordinal numbers ending in 1 but not 11 | ||
| // When the number ends with 1 but is not 11, | ||
| // Then the function should return the correct 'st' suffix | ||
| test("should return '21st' for 21", () => { | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| }); | ||
|
|
||
| // Case 5: Identify ordinal numbers ending in 2 but not 12 | ||
| // When the number ends with 2 but is not 12, | ||
| // Then the function should return the correct 'nd' suffix | ||
| test("should return '42nd' for 42", () => { | ||
| expect(getOrdinalNumber(42)).toEqual("42nd"); | ||
| }); | ||
|
|
||
| // continue testing and implementing getOrdinalNumber for additional cases | ||
| // Write your tests using Jest - remember to run your tests often for continual feedback | ||
| // Case 6: Identify ordinal numbers ending in 3 but not 13 | ||
| // When the number ends with 3 but is not 13, | ||
| // Then the function should return the correct 'rd' suffix | ||
| test("should return '53rd' for 53", () => { | ||
| expect(getOrdinalNumber(53)).toEqual("53rd"); | ||
| }); | ||
|
|
||
| // Case 1: Identify the ordinal number for 1 | ||
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
| // Case 7: Identify teen exceptions 11, 12, 13 | ||
| // When the number is 11, 12, or 13, | ||
| // Then the function should return the correct 'th' suffix | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
| test("should return '12th' for 12", () => { | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| }); | ||
| test("should return '13th' for 13", () => { | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| // Case 8: Identify general 'th' endings | ||
| // When the number does not end in 1, 2, or 3 (except teens), | ||
| // Then the function should return the 'th' suffix | ||
| test("should return '20th' for 20", () => { | ||
| expect(getOrdinalNumber(20)).toEqual("20th"); | ||
| }); | ||
| test("should return '100th' for 100", () => { | ||
| expect(getOrdinalNumber(100)).toEqual("100th"); | ||
| }); | ||
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,5 +1,8 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Count cannot be negative"); | ||
| } | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
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,32 +1,31 @@ | ||
| // Implement a function repeatStr | ||
| const repeatStr = require("./repeat-str"); | ||
| // Given a target string str and a positive integer count, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should: | ||
|
|
||
| // case: repeat String: | ||
| // Given a target string str and a positive integer count, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should repeat the str count times and return a new string containing the repeated str values. | ||
|
|
||
| test("should repeat the string count times", () => { | ||
| const str = "hello"; | ||
| const count = 3; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hellohellohello"); | ||
| }); | ||
|
|
||
| // case: handle Count of 1: | ||
| // Given a target string str and a count equal to 1, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. | ||
| test("should return original string when count is 1", () => { | ||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
|
|
||
| // case: Handle Count of 0: | ||
| // Given a target string str and a count equal to 0, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return an empty string, ensuring that a count of 0 results in an empty output. | ||
| test("should return empty string when count is 0", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
|
|
||
| // case: Negative Count: | ||
| // Given a target string str and a negative integer count, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should throw an error or return an appropriate error message, as negative counts are not valid. | ||
| test("should throw an error for negative count", () => { | ||
| const str = "hello"; | ||
| const count = -3; | ||
| expect(() => repeatStr(str, count)).toThrow(); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.