-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | 26-Jan-ITP | Seti Mussa | Sprint 3 | coursework implement and rewrite #1276
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
Changes from all commits
dfdbad9
f54aa1f
3be8b88
3bb3ca7
f376a88
f33a9a9
61867b6
8c62675
5920b75
3d96413
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Implement a function isProperFraction, | ||
| (properfraction (// Implement a function isProperFraction, | ||
| // when given two numbers, a numerator and a denominator, it should return true if | ||
| // the given numbers form a proper fraction, and false otherwise. | ||
|
|
||
|
|
@@ -11,12 +11,16 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| if (numerator < denominator) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
|
Comment on lines
+14
to
+18
Contributor
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.
|
||
| } | ||
| module.exports = isProperFraction; | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = isProperFraction; | ||
|
|
||
| // Here's our helper again | ||
| function assertEquals(actualOutput, targetOutput) { | ||
|
|
@@ -31,3 +35,24 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), true); | ||
| //Test | ||
| // Proper fraction | ||
| assertEqual(isProperFraction(3,5), true); | ||
| assertEual(isProperFraction(4,8), true); | ||
| assertEqual(isproperFraction(-1,2), true); | ||
| assertEqual(isProperFraction(-1,-2), true); | ||
| assertEqual(ispProperFraction(1,-2), true) | ||
|
|
||
|
|
||
| //Not | ||
| assertEqual(isproperFraction(9/7), false); | ||
| assertEqual(isproperFracton(13/11), false); | ||
| assertEqual(isproperFracton (19/10), false); | ||
| assertEqual(isproperFracton (17/3 ), false); | ||
|
|
||
|
|
||
|
|
||
| //Edge case | ||
| assertEqual(isperoperFractio(0/5), true); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,27 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const rank = card.slice(0, -1); | ||
| const suit = card.slice(-1); | ||
|
|
||
| const vaildSuits = ["♠", "♥", "♦", "♣"]; | ||
| const vailRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","k"]; | ||
|
|
||
| if (!vaildSuits.includes(suit) || !validRanks.inculdes(rank)){ | ||
| throw new Error("Invaild card"); | ||
| } | ||
| if (rank === "A") return 11; | ||
| if (rank === "J" || rank === "Q" || rank === "K") return 10; | ||
|
|
||
| return Number(rank); | ||
| } | ||
|
Comment on lines
+25
to
38
Contributor
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.
|
||
|
|
||
| module.exports = getCardValue; | ||
|
|
||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = getCardValue; | ||
|
|
||
|
|
||
| // Helper functions to make our assertions easier to read. | ||
| function assertEquals(actualOutput, targetOutput) { | ||
|
|
@@ -40,10 +55,15 @@ function assertEquals(actualOutput, targetOutput) { | |
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
| //Test | ||
| assertEquals(getCardvalue("A♠"), 11); | ||
| assertEquals(getCardEqual("J♣), 10); | ||
| assertEquals(getCardequal("10♥"), 10); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
|
|
||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card"); | ||
|
|
||
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.
The file has syntax errors and the indentation is off. Can you fix them?