-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | ITP-Jan-26| Mona_Eltantawy | Sprint 3 | Sprint 3/ implement and werite #1280
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
base: main
Are you sure you want to change the base?
Changes from all commits
646d6a5
bc93560
9f2ebc3
8f148b8
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 |
|---|---|---|
|
|
@@ -11,6 +11,11 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if( numerator < denominator) { | ||
| return true; | ||
| } | ||
|
Comment on lines
+14
to
+16
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. Can you lookup if -1/-2, 1/-2, -1/2, 1/0, -1/0 are considered proper fractions, and then update |
||
| else {return false; } | ||
|
|
||
| // TODO: Implement this function | ||
| } | ||
|
|
||
|
|
@@ -31,3 +36,18 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), true); | ||
| // inproper fraction: | ||
| assertEquals (isProperFraction(5, 3), false ); | ||
|
|
||
| // equal numbers | ||
| assertEquals (isProperFraction(4, 4), false ); | ||
|
|
||
| // negative numbers | ||
| assertEquals (isProperFraction(-2, 4), true ); | ||
| assertEquals (isProperFraction(5, -4), false ); | ||
| assertEquals (isProperFraction (-3,-5), false); | ||
|
|
||
| // special case | ||
| assertEquals(isProperFraction(1,0) , false); | ||
|
|
||
| assertEquals (isProperFraction (0,5), true); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,31 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const suit = card.slice(-1); | ||
| const rank = card.slice(0, -1); | ||
|
|
||
| if (suit !== "♠" && suit !== "♥" && suit !== "♦" && suit !== "♣") { | ||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| if (rank === "A") { | ||
| return 11; | ||
| } | ||
|
|
||
| if (rank === "J" || rank === "Q" || rank === "K") { | ||
| return 10; | ||
| } | ||
|
|
||
| if (rank >= "2" && rank <= "10") { | ||
| return Number(rank); | ||
| } | ||
|
Comment on lines
+40
to
+42
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. I don't think this function can pass all the tests you have prepared. |
||
|
|
||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| // TODO: Implement this function | ||
|
|
||
|
|
||
| // 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; | ||
|
|
@@ -40,6 +62,16 @@ function assertEquals(actualOutput, targetOutput) { | |
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
| assertEquals(getCardValue("2♠"), 2); | ||
| assertEquals(getCardValue("10♦"), 10); | ||
|
|
||
| // Face cards | ||
| assertEquals(getCardValue("J♣"), 10); | ||
| assertEquals(getCardValue("Q♥"), 10); | ||
| assertEquals(getCardValue("K♦"), 10); | ||
|
|
||
| // Ace | ||
| assertEquals(getCardValue("A♠"), 11); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
|
|
@@ -49,4 +81,15 @@ try { | |
| console.error("Error was not thrown for invalid card"); | ||
| } catch (e) {} | ||
|
|
||
|
|
||
| // What other invalid card cases can you think of? | ||
|
|
||
| const invalidCards = ["invalid", "1♠", "B♣", "10?", "Z♠"]; | ||
| for (const card of invalidCards) { | ||
| try { | ||
| getCardValue(card); | ||
| console.error(`Error was not thrown for invalid card: ${card}`); | ||
| } catch (e) { | ||
| // Expected error, do nothing | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,35 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { | |
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when (angle=== 90)`, () => { | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
|
|
||
| // Case 3: Obtuse angles | ||
| test (`should return "Obtuse angle" when (90 < angle < 180)` ,() =>{ | ||
|
|
||
| expect(getAngleType(95)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(100)).toEqual("Obtuse angle"); | ||
| }); | ||
|
|
||
| // Case 4: Straight angle | ||
| test (`should return "Straight angle" when ( angle === 180)` ,() =>{ | ||
|
|
||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
|
|
||
| }); | ||
| // Case 5: Reflex angles | ||
| test (`should return "Reflex angle" when (180 < angle < 360)` ,() =>{ | ||
|
|
||
| expect(getAngleType(190)).toEqual("Reflex angle"); | ||
| expect(getAngleType(300)).toEqual("Reflex angle"); | ||
| expect(getAngleType(200)).toEqual("Reflex angle"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
| test (`should return "Invalid angle" when (angle <= 0 or angle > 360)` ,() => { | ||
|
|
||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(400)).toEqual("Invalid angle"); | ||
| expect(getAngleType(-10)).toEqual("Invalid angle"); | ||
| }); | ||
|
Comment on lines
+43
to
+48
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. Could consider testing both boundary cases. |
||
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.
Spacing around the operator is not consistent.
If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.
If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
settings.jsonand set Prettier as the default formatter for JS.See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode