Repository navigation
London | 26-ITP-Sep | Hanna Bohlin | Sprint 2 | Practice TDD #1720
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
habohlin
wants to merge
48
commits into
CodeYourFuture:main
Choose a base branch
from
habohlin: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 all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
38dbbd8
Add test with different string length, it fails
habohlin 6b5df27
Refactor countChar to make prev test pass
habohlin ffcf1f9
Add test for varying chars in string, it fails
habohlin 9f80255
Refactor countChar to make prev test pass
habohlin b7fcec6
Add test for any char that exists in string, it fails
habohlin 626f314
Refactor countChar to make prev test pass
habohlin b184661
Add test for char NOT in string, returns 0, test passes already
habohlin e59481e
Add test for count is 1, str is 'hello', it fails
habohlin ce8ef88
Refactor repeatStr to pass prev test
habohlin 3da27c9
Add test for count is 0, str is 'hello', should return empty string, …
habohlin ece5aaf
Refactor repeatStr to pass prev test
habohlin 41c6f58
Add test for count is 4, test fails
habohlin c4ed549
Refactor repeatStr to be dynamic, and pass prev test
habohlin dbb63f0
Add test for count is negative, should throw error, test fails
habohlin d8bc6e0
Refactor repeatString to throw error and refactor the test, it passes
habohlin 43522a0
Add test for dynamic string value, it fails
habohlin 54e7f2e
Refactor repeatStr to use dynamic string in output, prev test now passes
habohlin 5739486
Refactor function to pass the failing tests
habohlin 6721f24
Add tests for numbers ending with 11, they fail
habohlin 582352f
Refactor function to pass prev tests
habohlin ed6c46c
Add tests for number ending 2 but not 12, they fail
habohlin 8ad33fc
Refactor function to pass prev tests
habohlin b21915a
Add tests for numbers ending with 12, they fail
habohlin 4ef1b43
Refactor function to pass prev tests
habohlin 8d41b97
Add tests for numbers ending 3 but not 13, they fail
habohlin 719b29d
Refactor function to pass prev tests
habohlin c4fa2c6
Add tests for numbers ending 13, they fail
habohlin 5c15ff4
Refactor function to pass prev tests
habohlin 7b78cdd
Add tests for all other whole numbers, they fail
habohlin eae160f
Refactor function to pass prev tests
habohlin c032f5b
Add test for throwing error when decimal number passed. Test fails
habohlin 8614766
Refactor function to pass prev test
habohlin 8c54303
Add test for missing argument, it passes on the same premise as the l…
habohlin 74f5c33
Add test for a passed string, it also passes thanks to the same check
habohlin 23e9048
Add test for undefined, it passes as well due to the same reason
habohlin 803ce36
Add test for num is null to throw error, it fails
habohlin 5a8d70f
Refactor function to pass prev test
habohlin ceaec78
Add test for num is false should throw error, it passes
habohlin 63998f9
Add test for num is true to throw error, it fails
habohlin 0aa534c
Refactor function to pass prev test
habohlin 1724b9a
Add test for num is array to throw error, it fails
habohlin 330bd08
Refactor function to pass prev test
habohlin 9574101
Add test for num is object to throw error, it passes
habohlin c939e57
Format files with prettier
habohlin 9633c24
Change numOfa variable name to be more descriptive
habohlin 441d1bf
Refactor and merge if statements leading to the same result
habohlin 4abb6da
Separate test group into 2 groups and remove some tests
habohlin dee4647
Merge two tests into 1, and change test names to be more generic
habohlin 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,3 +1,11 @@ | ||
| export function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let numOfChar = 0; | ||
|
|
||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters.charAt(i) === findCharacter) { | ||
| numOfChar++; | ||
| } | ||
| } | ||
|
|
||
| return numOfChar; | ||
| } |
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,3 +1,27 @@ | ||
| export function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if (num % 1 !== 0 || !num || typeof num !== "number" || num.length > 1) { | ||
| throw new Error("Error: whole number is needed"); | ||
| } | ||
|
|
||
| if ( | ||
| (num - 11) % 100 === 0 || | ||
| (num - 12) % 100 === 0 || | ||
| (num - 13) % 100 === 0 | ||
| ) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| if ((num - 1) % 10 === 0) { | ||
| return num + "st"; | ||
| } | ||
|
|
||
| if ((num - 2) % 10 === 0) { | ||
| return num + "nd"; | ||
| } | ||
|
|
||
| if ((num - 3) % 10 === 0) { | ||
| return num + "rd"; | ||
| } | ||
|
|
||
| return num + "th"; | ||
| } |
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,13 @@ | ||
| export function repeatStr() { | ||
| // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). | ||
| // The goal is to re-implement that function, not to use it. | ||
| return "hellohellohello"; | ||
| export function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("/Error: count should be non negative integer/"); | ||
| } | ||
|
|
||
| let repeatedStr = ""; | ||
|
|
||
| for (let i = 0; i < count; i++) { | ||
| repeatedStr += str; | ||
| } | ||
|
|
||
| return repeatedStr; | ||
| } |
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
Oops, something went wrong.
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.
Great separation of behaviours for this test suite! 👌