-
-
Notifications
You must be signed in to change notification settings - Fork 391
London | 25 -ITP-May | Dagim Daniel | Sprint 3 | implement and rewrite-test with jest #1473
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
Dagim-Daniel
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
Dagim-Daniel:coursework/sprint--3-implement-and-rewrite
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
7 commits
Select commit
Hold shift + click to select a range
e3ae6db
Sprint 3 from implement and rewrite - i have done the implement part …
Dagim-Daniel c822d53
sprint 3 implement and rewrite - i modified the implement part of …
Dagim-Daniel 3538f28
Revert "sprint 3 implement and rewrite - i modified the implement …
Dagim-Daniel b37f1b2
Sprint 3 all tasks under implement and rewrite-tests with jest has be…
Dagim-Daniel 927466a
Sprint 3 implement and rewrite-test with jest is done, i modified ge…
Dagim-Daniel 3c016e7
Revert "Sprint 3 implement and rewrite-test with jest is done, i mod…
Dagim-Daniel 4d1bf8c
Sprint 3 implement and rewrite-test with jest has been done
Dagim-Daniel 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
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 |
|---|---|---|
|
|
@@ -12,6 +12,14 @@ | |
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| numerator = Math.abs(numerator); | ||
| denominator = Math.abs(denominator); | ||
| if (numerator<denominator) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this if condition be simplified? |
||
| { | ||
| return true; | ||
| } | ||
| else | ||
| return false; | ||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -29,5 +37,12 @@ function assertEquals(actualOutput, targetOutput) { | |
| // TODO: Write tests to cover all cases. | ||
| // What combinations of numerators and denominators should you test? | ||
|
|
||
| // Example: 1/2 is a proper fraction | ||
| // Example: 1/2 is a proper fraction. | ||
| assertEquals(isProperFraction(1, 2), true); | ||
|
|
||
| assertEquals(isProperFraction(1,1),false); | ||
| assertEquals(isProperFraction(40234,98543),true); | ||
| assertEquals(isProperFraction(2,1),false); | ||
| assertEquals(isProperFraction(-10,-1),false); | ||
| assertEquals(isProperFraction(-1,-10),true); | ||
| assertEquals(isProperFraction(1.5,1),false); | ||
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 |
|---|---|---|
|
|
@@ -23,6 +23,29 @@ | |
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const value = card.slice(0, -1).toUpperCase(); | ||
| const validSuits = "♠,♥,♦,♣".split(","); | ||
| const suit = card.slice(-1); | ||
|
|
||
|
|
||
| if(!validSuits.includes(suit)) { | ||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10}; | ||
|
|
||
| if(faceCardValues[value] === undefined && (Number(value) < 2 || Number(value) > 10)) { | ||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| if (faceCardValues[value] !== undefined) { | ||
| return faceCardValues[value]; | ||
| } | ||
|
|
||
| const numvalue = Number(value); | ||
| if (numvalue >= 2 && numvalue <= 10) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this if condition need to be here? (Hint: compare it to the earlier if conditions) |
||
| return numvalue; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -41,6 +64,14 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
|
|
||
| assertEquals(getCardValue("A♥"),11); | ||
| assertEquals(getCardValue("10♠"),10); | ||
|
|
||
|
|
||
| assertEquals(getCardValue("2♠"), 2); | ||
| assertEquals(getCardValue("K♠"), 10); | ||
| assertEquals(getCardValue("q♦"), 10); | ||
| assertEquals(getCardValue("J♣"), 10); | ||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
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
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.
Did you remember to format this code?