-
-
Notifications
You must be signed in to change notification settings - Fork 338
Manchester | 26-ITP-JAN | Abdu Mussa | Sprint 3 |1-implement-and-rewriting-tests/ #1141
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
b1f57bf
2395603
ec69eea
9f67b6c
969c076
19b1d13
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 |
|---|---|---|
|
|
@@ -16,6 +16,12 @@ | |
|
|
||
| function getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| if (angle > 0 && angle < 90) return "Acute angle"; | ||
| else if (angle === 90) return "Right angle"; | ||
| else if (90 < angle && angle < 180) return "Obtuse angle"; | ||
| else if (angle === 180) return "Straight angle"; | ||
| else if (180 < angle && angle < 360) return "Reflex angle"; | ||
| else return "Invalid angle"; | ||
| } | ||
|
|
||
| // The line below allows us to load the getAngleType function into tests in other files. | ||
|
|
@@ -35,3 +41,31 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| let acute = getAngleType(1); | ||
|
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. This is very readable, and there is nothing wrong with that. But do you think you need to declare/reassign a variable for each test? How could you make this simpler and less lines of code? |
||
| assertEquals(acute, "Acute angle"); | ||
| acute = getAngleType(45); | ||
| assertEquals(acute, "Acute angle"); | ||
| acute = getAngleType(89); | ||
| assertEquals(acute, "Acute angle"); | ||
| let obtuse = getAngleType(91); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
| obtuse = getAngleType(100); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
| obtuse = getAngleType(179); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
| const straight = getAngleType(180); | ||
| assertEquals(straight, "Straight angle"); | ||
| let reflex = getAngleType(200); | ||
| assertEquals(reflex, "Reflex angle"); | ||
| reflex = getAngleType(243); | ||
| assertEquals(reflex, "Reflex angle"); | ||
| reflex = getAngleType(359); | ||
| assertEquals(reflex, "Reflex angle"); | ||
| let invalid = getAngleType(-11); | ||
| assertEquals(invalid, "Invalid angle"); | ||
| invalid = getAngleType(0); | ||
| assertEquals(invalid, "Invalid angle"); | ||
| invalid = getAngleType(360); | ||
| assertEquals(invalid, "Invalid angle"); | ||
| invalid = getAngleType(371); | ||
| assertEquals(invalid, "Invalid angle"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,42 @@ | |
| // Acceptance criteria: | ||
| // After you have implemented the function, write tests to cover all the cases, and | ||
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| if (!card || typeof card !== "string") { | ||
| throw new Error("Invalid card"); | ||
| } | ||
| // | ||
| const validSuits = ["♠", "♥", "♦", "♣"]; | ||
| const suit = card.slice(-1); //takes the last character of the string. | ||
| const rank = card.slice(0, -1); //takes everything except the last character. | ||
|
|
||
| if (!validSuits.includes(suit)) { | ||
| throw new Error("Invalid card"); // This if statement checks the suit is valid with the Array of suit we assigned | ||
| } | ||
| // Based on the question i get form mentor i changed the function if statement for better experience of the code. | ||
| const cardValues = { | ||
|
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. Do you think there is a better data type to use for a set of cards? 😉 |
||
| A: 11, | ||
| J: 10, | ||
| Q: 10, | ||
| K: 10, | ||
| 2: 2, | ||
| 3: 3, | ||
| 4: 4, | ||
| 5: 5, | ||
| 6: 6, | ||
| 7: 7, | ||
| 8: 8, | ||
| 9: 9, | ||
| 10: 10, | ||
| }; // This is java script object that act as like lookup table for the valid card value input. | ||
|
|
||
| if (cardValues[rank] !== undefined) return cardValues[rank]; | ||
| throw new Error("Invalid card"); | ||
| } | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
|
|
||
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.
There are quite a lot of conditionals in here. Do you think there is something other than if-else that could make this simpler, cleaner?