Skip to content

Commit

Permalink
darts: add tests to disallow absolute addition (#1488)
Browse files Browse the repository at this point in the history
* darts: add tests to disallow absolute addition

The current tests allow an erroneous-but-passing solution where the sum of the absolute values of the coordinates of the dart are compared to the radius thresholds (ie return 5 if `abs(x) + abs(y)` is greater than 1 but less than or equal to 5), rather than the calculated distance of the dart from the origin. Thanks to grwkremilek for the find.
  • Loading branch information
yawpitch authored and ErikSchierboom committed Mar 29, 2019
1 parent 3562b95 commit bac9381
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion exercises/darts/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exercise": "darts",
"version": "1.1.0",
"version": "1.2.0",
"cases": [
{
"description": "Return the correct amount earned by a dart landing in a given point in the target problem.",
Expand Down Expand Up @@ -67,6 +67,33 @@
"y": -0.1
},
"expected": 10
},
{
"property": "score",
"description": "A dart whose coordinates sum to > 1 but whose radius to origin is <= 1 is scored in the inner circle",
"input": {
"x": 0.4,
"y": 0.8
},
"expected": 10
},
{
"property": "score",
"description": "A dart whose coordinates sum to > 5 but whose radius to origin is <= 5 is scored in the middle circle",
"input": {
"x": 2,
"y": 4
},
"expected": 5
},
{
"property": "score",
"description": "A dart whose coordinates sum to > 10 but whose radius to origin is <= 10 is scored in the outer circle",
"input": {
"x": 4,
"y": 8
},
"expected": 1
}
]
}
Expand Down

0 comments on commit bac9381

Please sign in to comment.