Skip to content

darts: augment test suite#1448

Merged
ErikSchierboom merged 1 commit intoexercism:masterfrom
juhlig:improve_darts
Feb 1, 2019
Merged

darts: augment test suite#1448
ErikSchierboom merged 1 commit intoexercism:masterfrom
juhlig:improve_darts

Conversation

@juhlig
Copy link
Copy Markdown
Contributor

@juhlig juhlig commented Jan 22, 2019

I was just mentoring an exercise where the students solution treated the target as a square (as opposed to a circle), and was surprised that it nevertheless passed the tests.

I found that they only (except for one, that accidentially works still) use coordinates where one of them is 0, which also works if the solution calculates scores as if the target was a square.

I also noticed that, while the target is supposed to be a circle centered at (0, 0), so that there are valid target areas with negative coordinates, there are no test cases that provide negative coordinates at all.

@juhlig juhlig requested a review from ErikSchierboom January 23, 2019 09:16
Copy link
Copy Markdown
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding those additional tests for negative cases seems like a good addition! I'm wondering a little bit about the number of test cases, and if it perhaps were possible to be less exhaustive but still do the same checks (negative/non-negative, border/center, etc.). Do you think that would be possible?

@juhlig
Copy link
Copy Markdown
Contributor Author

juhlig commented Jan 23, 2019

The tests already combine coordinate signedness and target area/shape into one. There is a test for well away from the target, outside but near the target, and then, roughly, for each ring, it tests a hit on the very border, in the middle of the ring at a zero-coordinate, in middle of the ring at a 45° angle, and in the ring but near the border to another ring at a 45° angle (this is where tests would fail if the target was treated as a square instead of a circle in a solution). The coordinates "rotate" around at the same time, starting at negative x and positive y, to positive x and positive y, to positive x and negative y, and so on.

I'm not sure which to drop. The way-outdside-the-target test could go. Other obvious candidates are those for the middle of the ring at a zero-coordinate, they serve no definite purpose, but there are only 2 of those. Next could be those at the middle of a ring at a 45° angle, there are 2 of those as well. The tests for hits at the very border should stay, I would say, as should the tests for hits near the border to another ring. And the center hit should be there as well, since where is the fun in a dart match if you don't have one of those ;).

@ErikSchierboom
Copy link
Copy Markdown
Member

The way I perhaps would go about this is to modify some of the existing test cases to use negative values. E.g. one you use -3 here: https://github.com/exercism/problem-specifications/blob/master/exercises/darts/canonical-data.json#L30. This would probably mean also adding one new test cases, but I would really rather keep the number of test cases fairly small.

@juhlig
Copy link
Copy Markdown
Contributor Author

juhlig commented Jan 24, 2019

Ok, can do. But what actually prompted me to make this PR was that the existing test cases allowed for the target to be treated as a square (instead of a circle, as a dart target normally is, and is also mentioned in the instructions), and still pass. So, what I would do now, to keep the number of test cases small, is use the existing test cases with different coordinates, namely negative/positive mixed at points that will pass if the target is treated as a circle but fail if treated as a square. Would that be ok?

@ErikSchierboom
Copy link
Copy Markdown
Member

[...] use the existing test cases with different coordinates, namely negative/positive mixed at points that will pass if the target is treated as a circle but fail if treated as a square

To me, that is a great solution. I'd be curious to hear what @rpottsoh or @petertseng think about the best approach?

@rpottsoh
Copy link
Copy Markdown
Member

Alright.... I agree that negative values for X and Y be introduced. I think of a dart board more as a Polar system more than a Cartesian system. Since this is a mathy exercise I got to thinking that maybe it would be more interesting if the coordinates were Polar... There would not be any negative values.... A quick search lead me here. A nice explanation of converting from Cartesian to Polar and back.... Since we are thinking of a Cartesian system then we obviously should be considering the possibility of X and/or Y being negative as the coordinates locate a thrown dart having landed in one of the 4 quadrants of the Cartesian system.....

I am not quite sure at this point if it is better to add tests, alter existing tests, or both.... Perhaps as long as there is at least one case for each of the 4 quadrants would be a good enough change?

@ErikSchierboom
Copy link
Copy Markdown
Member

Perhaps as long as there is at least one case for each of the 4 quadrants would be a good enough change?

I agree! @juhlig do you think that is do-able?

@juhlig
Copy link
Copy Markdown
Contributor Author

juhlig commented Jan 28, 2019

It is doable, yes, but I don't fully agree. There should at least be tests for hits at the very borders between the rings (border hit counts as a hit to the more inward ring), as this ensures the proper usage of <and > vs >= and =<.

@ErikSchierboom
Copy link
Copy Markdown
Member

There should at least be tests for hits at the very borders between the rings

Alright. Perhaps you can add those as new test cases then?

@juhlig
Copy link
Copy Markdown
Contributor Author

juhlig commented Jan 28, 2019

Ok, done. There are 7 tests now, one for each quadrant, one for each border.

Copy link
Copy Markdown
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

"x": 15.3,
"y": 13.2
"x": -9,
"y": 9
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost had me thinking it was inside the target. I calculate the distance from the center to be ~12.7 so checks out for this case. 👍

Copy link
Copy Markdown
Member

@rpottsoh rpottsoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes all look good and check out for me. 👍 If there are not further objections/requests for changes then this should be merged in the next 24-48 hours.

Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the treatment of darts landing on borders doesn't seem consistent, based on what I have noted. I request an explanation of the rules, or a change to be consistent

"x": 5,
"y": 0
},
"expected": 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that here, the dart is treated as being in the smaller circle (here, the middle one) rather than the larger one (outer)

Comment thread exercises/darts/canonical-data.json Outdated
"y": 5
"y": -1
},
"expected": 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, the dart is treated as being in the larger circle (middle) rather than the smaller (inner)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this should count as a hit to the inner circle. Fixed in my last commit.

@ErikSchierboom
Copy link
Copy Markdown
Member

the treatment of darts landing on borders doesn't seem consistent, based on what I have noted. I request an explanation of the rules, or a change to be consistent

@juhlig @petertseng raises some valid points. Could you perhaps look at his comments?

The test suite does not include tests that ensure the target is treated as
a circle (as opposed to a square), and does not cover the left and lower
quadrants (where x and/or y would be negative).
@petertseng petertseng dismissed their stale review January 29, 2019 17:18

it's consistent now

@ErikSchierboom
Copy link
Copy Markdown
Member

@petertseng Could you see if your comments have been addressed?

@petertseng
Copy link
Copy Markdown
Member

I already ghave.

@ErikSchierboom
Copy link
Copy Markdown
Member

Ah sorry, I didn't see your name in the list of approvers.

@petertseng
Copy link
Copy Markdown
Member

it is a little too easy to miss it, since as of about 1-2 days ago dismissals still do not send a notification

@ErikSchierboom ErikSchierboom merged commit 17d157a into exercism:master Feb 1, 2019
@ErikSchierboom
Copy link
Copy Markdown
Member

Merged. Thanks @juhlig!

@juhlig juhlig deleted the improve_darts branch February 26, 2019 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants