Manchester | 26-ITP-May | Szidonia Bodo | Sprint 3 | Implement and review test#1520
Manchester | 26-ITP-May | Szidonia Bodo | Sprint 3 | Implement and review test#1520bodoszidi wants to merge 6 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| return true; | ||
| } else { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
If you ever find yourself with a solution that looks like
if (condition) {
return true;
} else {
return false;
}And the condition itself is a boolean value (i.e. it evaluates to true or false), there's a more succinct way we can write the code. Can you think what it might be?
| assertEquals(isProperFraction(-8, 2), false); | ||
| assertEquals(isProperFraction(4, 0), false); | ||
| assertEquals(isProperFraction(0, 0), false); | ||
| assertEquals(isProperFraction(-2, -2), false) |
There was a problem hiding this comment.
If you were to check the case of isProperFraction(-1, 2), what do we want to see as the answer? And would that test pass?
(Things get a little awkwardly mathsy with negative fractions, I recognise)
| return Number(removeSuit); | ||
| } else { | ||
| throw new Error("Error") | ||
| } |
There was a problem hiding this comment.
A great solution, very readable 👌
Just one point, you've declared let removeSuit - should this be a let or a const? In either case, why?
| assertEquals(getCardValue("J♦"), 10); | ||
| assertEquals(getCardValue("7♥"), 7); | ||
| assertEquals(getCardValue("A♥"), 11); | ||
| assertEquals(getCardValue("8♥"), 8); |
There was a problem hiding this comment.
When writing a test suite, we want to try and cover all possible "behaviours" of our function. Here I can see you've covered:
- Hearts
- Spades
- Diamonds
- Numbered cards
- Jacks
- Aces
Looking at that list, what have you not covered?
| test(`should return "Right angle" when (angle = 90)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (angle < 180, angle > 90)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(99)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" when (angle = 180)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (angle < 360, angle > 180)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(189)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| expect(getAngleType(199)).toEqual("Reflex angle"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angle" when (angle > 361, angle < 0)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(505)).toEqual("Invalid angle"); | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(699)).toEqual("Invalid angle"); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
You've left a comment in all these tests which doesn't seem relevant to them - get rid!
|
|
||
| test(`should return false when denominator is bigger than the numerator`, () => { | ||
| expect(isProperFraction(5, -2)).toEqual(false); | ||
| expect(isProperFraction(-1, 0)).toEqual(false); |
There was a problem hiding this comment.
expect(isProperFraction(-1, 0)).toEqual(false);
This test case, which test does it belong in? What grouping of behaviours does it fall into?
|
|
||
| test(`Should return 10 when given the Queen card`, () => { | ||
| expect(getCardValue("Q♠")).toEqual(10); | ||
| }); |
There was a problem hiding this comment.
The tests are pretty decent (maybe worth considering my above comment for whether there's a couple more you could add), but I want to talk about the test descriptions at the moment.
Generally speaking, we don't always want to be so specific as to describe exactly what's happening in the assertion. Think about the previous function, your test descriptions were great! You separated it into
- When the numerator is bigger than the denominator
- When the numerator is smaller than the denominator
Rather than saying "returns true when numerator is 4 and denominator is 6", which would be too specific.
Some of these tests are understandably individualised, such as testing for "Q♠" - there's a very specific input that will only produce one output. But on the contrary, your tests on lines 16, 24, and 28 are all really testing the same behaviour, so probably ought to be one test. My question for you is: what would be a good test description for that test?
|
Hey @bodoszidi! 👋 Good work on your first journey into using tests. Writing tests from scratch is not easy, it's a skill that takes a while to develop but there's a lot of good stuff in here. My comments are mostly about focussing on how to organise our test cases. The main things we want to be doing are:
Please do respond to any comments with answers or further questions if you aren't sure what I'm talking about! 😄 |
Self checklist
Changelist
Created a new pull request only for implementation and review test