Skip to content
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

darts: Add new exercise #1363

Merged
merged 10 commits into from
Oct 23, 2018
Merged
65 changes: 65 additions & 0 deletions exercises/darts/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"exercise": "darts",
"version": "1.0.0",
"cases": [
{
"description": "Return the correct amount earned by a dart landing in a given point in the target problem.",
"cases": [
{
"property": "result",
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps score would be a more descriptive propery name?

"description": "A dart lands outside the target",
"input": {
"x": 15.3,
"y": 13.2
},
"expected": 0
},
{
"property": "result",
"description": "A dart lands just in the border of the target",
"input": {
"x": 10,
"y": 0
},
"expected": 1
},
{
"property": "result",
"description": "Input is not a number",
Copy link
Contributor

Choose a reason for hiding this comment

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

According to this, expected should be an object containing one property, error, with its value being a string describing the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that any invalid input should return null. Maybe I should make it clear in the description, or go with the error. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

The convention is that an error condition should be formatted as follows: "expected": {"error": "empty stack"}
Each track implementing this exercise can then for itself decide how to represent the error case.

Copy link
Member

@rpottsoh rpottsoh Oct 10, 2018

Choose a reason for hiding this comment

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

I think the case should be excluded from the exercise. See #902 and #523. Since erroneous input is not covered in description.md I see no reason to cover it in test data.

Copy link
Member

Choose a reason for hiding this comment

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

@ramadis What do you think about excluding this (error) case from the exercise? @rpottsoh has linked to two relevant issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ErikSchierboom Yes, I'm inclined to go that way. I believe also that adding tests for inputs that are outside the problem domain in the problem specification could bring inconsistencies between implementations. Since, for example, a language with a strong type system (e.g. Haskell) shouldn't have to test for these cases since the program would not compile given incorrect input, and making it throw an exception would be counterproductive to the simplicity and core value of the problem.

So, I'll remove this test and keep going on!

"input": {
"x": "WRONG",
"y": 10
},
"expected": null
},
{
"property": "result",
"description": "A dart lands in the middle circle",
"input": {
"x": 3,
"y": 3.7
},
"expected": 5
},
{
"property": "result",
"description": "A dart lands right in the border between outside and middle circles",
"input": {
"x": 0,
"y": 5
},
"expected": 5
},
{
"property": "result",
"description": "A dart arrives in the inner circle",
ramadis marked this conversation as resolved.
Show resolved Hide resolved
"input": {
"x": 0,
"y": 0
},
"expected": 10
}
]
}
]
}
15 changes: 15 additions & 0 deletions exercises/darts/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Write a function that returns the earned points in a Darts game.

[Darts](https://en.wikipedia.org/wiki/Darts) is a game where players
throw darts to a [target](https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg).

In our particular instance of the game, the target rewards with 4 different amounts of points, depending on where the dart lands:

* If the dart lands outside the target, player earns no points (0 points).
* If the dart lands in the outer circle of the target, player earns 1 point.
* If the dart lands in the middle circle of the target, player earns 5 points.
* If the dart lands in the inner circle of the target, player earns 10 points.

The outer circle has a radius of 10 units (This is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered to the same point (That is, the circles are [concentrics](http://mathworld.wolfram.com/ConcentricCircles.html)).
Copy link
Member

Choose a reason for hiding this comment

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

concentric should be singular.


Write a function that given a point in the target (defined by its `real` cartesian coordinates `x` and `y`), returns the correct amount earned by a dart landing in that point.
3 changes: 3 additions & 0 deletions exercises/darts/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
blurb: "Write a function that returns the earned points in a Darts game"
source: "Inspired by an excersie created by a professor Della Paolera in Argentina"