Brussels | ITP-2026-1 | Benjamin Vanderzeypen | Sprint 3 | Coursework/sprint 3#66
Conversation
I also had to adjust 3-get-card-value.js because we were expected to have a "real" error message -> Invalid card.
| } | ||
| if (angle === 180) { | ||
| return "Straight angle"; | ||
| } else { |
There was a problem hiding this comment.
here, you could get rid of the else, as it will always fall here if none of the previous choices got choosed.
| // Then the function should return "Obtuse angle" | ||
| const obtuse = getAngleType(120); | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
| assertEquals(obtuse, "Obtuse angle"); |
There was a problem hiding this comment.
Here you see a good example of constant usage. You could have a constant for the string "Obtuse angle", so you don't have to repeat writing the string two times and get the risk a typo.
const ObstuseAngle = "Obstuse angle";
| // complete the rest of the tests and cases | ||
| // write one test at a time, and make it pass, build your solution up methodically | ||
|
|
||
| function isProperFraction(numerator, denominator) { |
There was a problem hiding this comment.
Some of the tests are failing. Something is msising on the function
There was a problem hiding this comment.
Wow! I totally missed that! I guess I wasn't awake yet 🐙 Thanks for running the tests again on my behalve to see what was wrong!
| @@ -8,8 +8,30 @@ | |||
| // write one test at a time, and make it pass, build your solution up methodically | |||
| // just make one change at a time -- don't rush -- programmers are deep and careful thinkers | |||
| function getCardValue(card) { | |||
There was a problem hiding this comment.
You can simplify the function considering the code below. So all the numeric values return themselves but as numbers instead of strings, so you dont need to repeat all of them.
else if (!isNaN(rank) && rank !== "") { return parseInt(rank, 10); }
| assertEquals(nineofClubs, 9); | ||
|
|
||
| // Handles invalid cards | ||
| const invalidCard = getCardValue("Z♠"); |
There was a problem hiding this comment.
Your function is not returning undefined when receiving an invalid parameter, but throwing an error instead. So this test assertion will never work.
You need to adjust your function in the test. As you wish.
There was a problem hiding this comment.
I'm fixing that now, but I had to do my research to find the perfect solution for this, we can do the test with try and catch.
nuttyproducer
left a comment
There was a problem hiding this comment.
I've refactored and fixed the tests to comply with all the coursework exercises.
Thank you again for reviewing @robertopaixao !
Changelist
We've created tests with assertEquals and with a testing environment named Jest.
Tests all run succesfull.
Questions
I've read that we can leave out the last "else" in a function.
For example:
It means we can close the function with only trow new Error("invalid card");
I haven't tested it but I guess it would work? Is this best practice for the future?