-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | May-2026-itp | Vitalii Kmit | Sprint 3 | Implement and rewrite tests #1463
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
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 |
|---|---|---|
|
|
@@ -15,7 +15,19 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| if (angle > 0 && angle < 90) { | ||
| return "Acute angle"; | ||
| } else if (angle == 90) { | ||
| return "Right angle"; | ||
| } else if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } else if (angle == 180) { | ||
|
Member
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. Same as above |
||
| return "Straight angle"; | ||
| } else if (angle > 180 && angle < 360) { | ||
| return "Reflex angle"; | ||
| } else { | ||
| return "Invalid angle"; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getAngleType function into tests in other files. | ||
|
|
@@ -31,7 +43,10 @@ function assertEquals(actualOutput, targetOutput) { | |
| ); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| assertEquals(getAngleType(90), "Right angle"); | ||
| assertEquals(getAngleType(45), "Acute angle"); | ||
| assertEquals(getAngleType(91), "Obtuse angle"); | ||
| assertEquals(getAngleType(180), "Straight angle"); | ||
| assertEquals(getAngleType(185), "Reflex angle"); | ||
| assertEquals(getAngleType(365), "Invalid angle"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,31 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const lastChar = card.length - 1; | ||
|
Member
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. The name of this variable suggests it contains a character. But it actually contains an index of a character. Can you think of a name that could make this more clear? |
||
| const rank = card.slice(0, lastChar); | ||
| const suit = card.slice(lastChar); | ||
|
|
||
| if (rank === "10") { | ||
|
Member
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 works, but I'm curious - why did you decide to handle 10 specially here? What would happen if someone passed the string |
||
| return 10; | ||
| } | ||
|
|
||
| if (card.length > 2) { | ||
| throw new Error("Invalid input length"); | ||
| } | ||
|
|
||
| if (!(suit === "♠" || suit === "♥" || suit === "♦" || suit === "♣")) { | ||
| throw new Error("Invalid suit ", suit); | ||
|
Member
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. It's often useful to include in an error message what the invalid data was. Imagine you're are running a big long programme, and aren't sure exactly what data is being processed - the more context we can give in errors the better. |
||
| } | ||
|
|
||
| if (rank == "A") { | ||
| return 11; | ||
| } else if (rank == "J" || rank == "Q" || rank == "K") { | ||
| return 10; | ||
| } else if (!isNaN(rank)) { | ||
| return Number(rank); | ||
| } else { | ||
| throw new Error("Invalid card"); | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
||
|
Member
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. Please revert the changes to this file, they're not relevant for this exercise. |
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.
Here you're using
==but JavaScript also has a===operator. Do you know the difference? Why have you chosen to use==here? When would===make more sense?This applies in many places in your PR - please take a look at them all!