generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 239
London | 25-ITP-September |Sophia Mohamed |Sprint 3 | 2 practice tdd #842
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
saff-coder
wants to merge
12
commits into
CodeYourFuture:main
Choose a base branch
from
saff-coder: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.
+112
−21
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7312985
All the tasks are complete
saff-coder 113d089
Merge pull request #1 from saff-coder/coursework/sprint-1
saff-coder d8fd187
completed the function now it should count how many char in a string
saff-coder 5c3f09f
Updated the CountChar function
saff-coder 2614707
implement countChar test done with Different Scenario
saff-coder c8c9bc1
function Updated
saff-coder 620ee39
test is done in different cases
saff-coder 745b6e9
function updated
saff-coder d6f14a8
test is done with different Numbers
saff-coder 45f409b
#reverted sprint 1commit
saff-coder 566278d
The test was edited
saff-coder 407bf05
more testing scenarios added
saff-coder 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,12 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| } | ||
| function countChar(str, char) { | ||
| let count = 0; | ||
|
|
||
| for (let i = 0; i < str.length; i++) {//loop through each character in the string | ||
| if (str[i] === char) {//check if the character matches the target character | ||
| count = count + 1; | ||
| } | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| return count;//return the final 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,43 @@ | ||
| // implement a function countChar that counts the number of times a character occurs in a string | ||
| const countChar = require("./count"); | ||
|
|
||
|
|
||
| // Given a string str and a single character char to search for, | ||
| // When the countChar function is called with these inputs, | ||
| // Then it should: | ||
| // Scenario: Single Occurrence | ||
|
|
||
| test("counts a single occurrence of a character", () => { | ||
| expect(countChar("hello", "h")).toEqual(1); | ||
| expect(countChar("world", "d")).toEqual(1); | ||
| }); | ||
| // Scenario: Multiple Occurrences | ||
| // Given the input string str, | ||
| // And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'), | ||
| // When the function is called with these inputs, | ||
| // Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa'). | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "aaaaa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| test("counts multiple occurrences of a character", () => { | ||
| expect(countChar("aaaaa", "a")).toEqual(5); | ||
| expect(countChar("banana", "a")).toEqual(3); | ||
| expect(countChar("mississippi", "s")).toEqual(4); | ||
| }); | ||
|
|
||
| //test("should count multiple occurrences of a character", () => { | ||
| // const str = "aaaaa"; | ||
| //const Char = "a"; | ||
| //const count = countChar(str,Char); | ||
| // expect(count).toEqual(5); | ||
| //}); | ||
|
|
||
| // Scenario: No Occurrences | ||
| // Given the input string str, | ||
| // And a character char that does not exist within the case-sensitive str, | ||
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. | ||
| // Scenario: No Occurrences | ||
| test("should return 0 if the character is not in the string", () => { | ||
| const str = "hello"; | ||
| const char = "x"; // character not present in str | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
|
|
||
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,22 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastTwoDigits = num % 100; // check the last 2 digits for 11,12,13 | ||
| const lastDigit = num % 10; | ||
|
|
||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| switch (lastDigit) { | ||
| case 1: | ||
| return num + "st"; | ||
| case 2: | ||
| return num + "nd"; | ||
| case 3: | ||
| return num + "rd"; | ||
| default: | ||
| 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,48 @@ | ||
| 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" | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| // Case 1: Numbers ending in 1 (but not 11) | ||
| test("append 'st' to numbers ending in 1, except those ending in 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| expect(getOrdinalNumber(111)).toEqual("111th"); // exception | ||
| }); | ||
|
|
||
| // Case 2: Numbers ending in 2 (but not 12) | ||
| 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(102)).toEqual("102nd"); | ||
| expect(getOrdinalNumber(112)).toEqual("112th"); // exception | ||
| }); | ||
| // Case 3: Numbers ending in 3 (but not 13) | ||
| test("append 'rd' to numbers ending in 3, except those ending in 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(103)).toEqual("103rd"); | ||
| expect(getOrdinalNumber(113)).toEqual("113th"); // exception | ||
| }); | ||
| // Case 4: Numbers ending in 4–9 or exceptions (11, 12, 13) | ||
| test("append 'th' to numbers ending in 4–9 or ending with 11, 12, or 13", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(9)).toEqual("9th"); | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); | ||
| // Optional: edge cases | ||
| test("should handle 0 and large numbers correctly", () => { | ||
| expect(getOrdinalNumber(0)).toBe("0th"); | ||
| expect(getOrdinalNumber(1000001)).toBe("1000001st"); // ends with 1, not teen | ||
| expect(getOrdinalNumber(1000012)).toBe("1000012th"); // ends with 12 -> teen | ||
|
|
||
| }); | ||
|
|
||
|
|
||
|
|
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 repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(word, times) { | ||
| if (times < 0) { | ||
| throw new Error("Count must be a non-negative number"); | ||
| } | ||
| return word.repeat(times); | ||
| } | ||
|
|
||
| module.exports = repeat; |
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.
To keep the code clean, why not delete all unused code?