Skip to content

Commit

Permalink
Update darts to v3 (exercism#646)
Browse files Browse the repository at this point in the history
* Updated unit tests for Darts from problem specification.

* Regenerated docs, metadata, tests of Darts exercise

* Fixed tag and hint for DartsTest class.

* Fixed typo in hints

* Fixed typo in hints file of output directory.
  • Loading branch information
Bajger authored Feb 24, 2025
1 parent d4fbc32 commit d906135
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 129 deletions.
9 changes: 5 additions & 4 deletions dev/src/Exercise@Darts/Darts.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
This is pretty straight forward if the soluton uses c = sqrt of a^2 + b^2
"
Class {
#name : #Darts,
#superclass : #Object,
#category : #'Exercise@Darts'
#name : 'Darts',
#superclass : 'Object',
#category : 'Exercise@Darts',
#package : 'Exercise@Darts'
}

{ #category : #scoring }
{ #category : 'scoring' }
Darts >> scoreX: anInteger y: anotherInteger [
| length |

Expand Down
189 changes: 135 additions & 54 deletions dev/src/Exercise@Darts/DartsTest.class.st
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
"
# Darts
Write a function that returns the earned points in a single toss of a Darts game.
# Description
[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).
Calculate the points scored in a single toss of a Darts game.
In our particular instance of the game, the target rewards with 4 different amounts of points, depending on where the dart lands:
[Darts][darts] is a game where players throw darts at a [target][darts-target].
* 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.
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
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 [concentric](http://mathworld.wolfram.com/ConcentricCircles.html)) defined by the coordinates (0, 0).
![Our dart scoreboard with values from a complete miss to a bullseye](https://assets.exercism.org/images/exercises/darts/darts-scoreboard.svg)
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.
- 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 at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0).
Given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), calculate the correct score earned by a dart landing at that point.
## Credit
The scoreboard image was created by [habere-et-dispertire][habere-et-dispertire] using [Inkscape][inkscape].
[darts]: https://en.wikipedia.org/wiki/Darts
[darts-target]: https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg
[concentric]: https://mathworld.wolfram.com/ConcentricCircles.html
[cartesian-coordinates]: https://www.mathsisfun.com/data/cartesian-coordinates.html
[real-numbers]: https://www.mathsisfun.com/numbers/real-numbers.html
[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire
[inkscape]: https://en.wikipedia.org/wiki/Inkscape
## Hint
The Pythagorean theorum will help.
The Pythagorean theorem will help.
"
Class {
#name : #DartsTest,
#superclass : #ExercismTest,
#name : 'DartsTest',
#superclass : 'ExercismTest',
#instVars : [
'dartsCalculator'
'darts'
],
#category : #'Exercise@Darts'
#category : 'Exercise@Darts',
#package : 'Exercise@Darts'
}

{ #category : #config }
{ #category : 'config' }
DartsTest class >> exercise [
"Answer the configured exercise meta data for this exercise, an ExercismExercise"

Expand All @@ -41,100 +58,164 @@ DartsTest class >> exercise [
yourself
]

{ #category : #config }
{ #category : 'config' }
DartsTest class >> uuid [
"Answer a unique id for this exercise"
^'a0df4a77-8720-4e1a-ac52-8060f1425a2b'
]

{ #category : #config }
{ #category : 'config' }
DartsTest class >> version [
"Generated from specification: 14 April 2019"
^'1.2.1'
]

{ #category : #running }
{ #category : 'running' }
DartsTest >> setUp [
super setUp.
dartsCalculator := Darts new
darts := Darts new
]

{ #category : #tests }
DartsTest >> test01_ADartLandsOutsideTheTarget [
{ #category : 'tests' }
DartsTest >> test01_MissedTarget [
"Tip: Remember to review the class [Comment] tab"
<exeTestName: 'Missed target'>
<exeTestUUID: '9033f731-0a3a-4d9c-b1c0-34a1c8362afb'>

| result |

result := dartsCalculator scoreX: -9 y: 9 .
result := darts scoreX: -9 y: 9 .
self assert: result equals: 0
]

{ #category : #tests }
DartsTest >> test02_ADartLandsJustInTheBorderOfTheTarget [
{ #category : 'tests' }
DartsTest >> test02_OnTheOuterCircle [
<exeTestName: 'On the outer circle'>
<exeTestUUID: '4c9f6ff4-c489-45fd-be8a-1fcb08b4d0ba'>

| result |

result := dartsCalculator scoreX: 0 y: 10 .
result := darts scoreX: 0 y: 10 .
self assert: result equals: 1
]

{ #category : #tests }
DartsTest >> test03_ADartLandsInTheOuterCircle [
{ #category : 'tests' }
DartsTest >> test03_OnTheMiddleCircle [
<exeTestName: 'On the middle circle'>
<exeTestUUID: '14378687-ee58-4c9b-a323-b089d5274be8'>

| result |

result := dartsCalculator scoreX: 4 y: 4 .
self assert: result equals: 1
result := darts scoreX: -5 y: 0 .
self assert: result equals: 5
]

{ #category : #tests }
DartsTest >> test04_ADartLandsRightInTheBorderBetweenOuterAndMiddleCircles [
{ #category : 'tests' }
DartsTest >> test04_OnTheInnerCircle [
<exeTestName: 'On the inner circle'>
<exeTestUUID: '849e2e63-85bd-4fed-bc3b-781ae962e2c9'>

| result |

result := dartsCalculator scoreX: 5 y: 0 .
self assert: result equals: 5
result := darts scoreX: 0 y: -1 .
self assert: result equals: 10
]

{ #category : #tests }
DartsTest >> test05_ADartLandsInTheMiddleCircle [
{ #category : 'tests' }
DartsTest >> test05_ExactlyOnCenter [
<exeTestName: 'Exactly on center'>
<exeTestUUID: '1c5ffd9f-ea66-462f-9f06-a1303de5a226'>

| result |

result := dartsCalculator scoreX: 0.8 y: -0.8 .
self assert: result equals: 5
result := darts scoreX: 0 y: 0 .
self assert: result equals: 10
]

{ #category : #tests }
DartsTest >> test06_ADartLandsRightInTheBorderBetweenMiddleAndInnerCircles [
{ #category : 'tests' }
DartsTest >> test06_NearTheCenter [
<exeTestName: 'Near the center'>
<exeTestUUID: 'b65abce3-a679-4550-8115-4b74bda06088'>

| result |

result := dartsCalculator scoreX: 0 y: -1 .
result := darts scoreX: -0.1 y: -0.1 .
self assert: result equals: 10
]

{ #category : #tests }
DartsTest >> test07_ADartLandsInTheInnerCircle [
{ #category : 'tests' }
DartsTest >> test07_JustWithinTheInnerCircle [
<exeTestName: 'Just within the inner circle'>
<exeTestUUID: '66c29c1d-44f5-40cf-9927-e09a1305b399'>

| result |

result := dartsCalculator scoreX: -0.1 y: -0.1 .
result := darts scoreX: 0.7 y: 0.7 .
self assert: result equals: 10
]

{ #category : #tests }
DartsTest >> test08_ADartWhoseCoordinatesSumToGreaterThan1ButWhoseRadiusToOriginIsLessThanOrEqualTo1IsScoredInTheInnerCircle [
{ #category : 'tests' }
DartsTest >> test08_JustOutsideTheInnerCircle [
<exeTestName: 'Just outside the inner circle'>
<exeTestUUID: 'd1012f63-c97c-4394-b944-7beb3d0b141a'>

| result |

result := dartsCalculator scoreX: 0.4 y: 0.8 .
self assert: result equals: 10
result := darts scoreX: 0.8 y: -0.8 .
self assert: result equals: 5
]

{ #category : #tests }
DartsTest >> test09_ADartWhoseCoordinatesSumToGreaterThan5ButWhoseRadiusToOriginIsLessThanOrEqualTo5IsScoredInTheMiddleCircle [
{ #category : 'tests' }
DartsTest >> test09_JustWithinTheMiddleCircle [
<exeTestName: 'Just within the middle circle'>
<exeTestUUID: 'ab2b5666-b0b4-49c3-9b27-205e790ed945'>

| result |

result := dartsCalculator scoreX: 2 y: 4 .
result := darts scoreX: -3.5 y: 3.5 .
self assert: result equals: 5
]

{ #category : #tests }
DartsTest >> test10_ADartWhoseCoordinatesSumToGreaterThan10ButWhoseRadiusToOriginIsLessThanOrEqualTo10IsScoredInTheOuterCircle [
{ #category : 'tests' }
DartsTest >> test10_JustOutsideTheMiddleCircle [
<exeTestName: 'Just outside the middle circle'>
<exeTestUUID: '70f1424e-d690-4860-8caf-9740a52c0161'>

| result |

result := darts scoreX: -3.6 y: -3.6 .
self assert: result equals: 1
]

{ #category : 'tests' }
DartsTest >> test11_JustWithinTheOuterCircle [
<exeTestName: 'Just within the outer circle'>
<exeTestUUID: 'a7dbf8db-419c-4712-8a7f-67602b69b293'>

| result |

result := dartsCalculator scoreX: 4 y: 8 .
result := darts scoreX: -7.0 y: 7.0 .
self assert: result equals: 1
]

{ #category : 'tests' }
DartsTest >> test12_JustOutsideTheOuterCircle [
<exeTestName: 'Just outside the outer circle'>
<exeTestUUID: 'e0f39315-9f9a-4546-96e4-a9475b885aa7'>

| result |

result := darts scoreX: 7.1 y: -7.1 .
self assert: result equals: 0
]

{ #category : 'tests' }
DartsTest >> test13_AsymmetricPositionBetweenTheInnerAndMiddleCircles [
<exeTestName: 'Asymmetric position between the inner and middle circles'>
<exeTestUUID: '045d7d18-d863-4229-818e-b50828c75d19'>

| result |

result := darts scoreX: 0.5 y: -4 .
self assert: result equals: 5
]
2 changes: 1 addition & 1 deletion dev/src/Exercise@Darts/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Exercise@Darts' }
Package { #name : 'Exercise@Darts' }
3 changes: 0 additions & 3 deletions exercises/practice/darts/.docs/instructions.append.md

This file was deleted.

4 changes: 2 additions & 2 deletions exercises/practice/darts/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instructions

Write a function that returns the earned points in a single toss of a Darts game.
Calculate the points scored in a single toss of a Darts game.

[Darts][darts] is a game where players throw darts at a [target][darts-target].

Expand All @@ -16,7 +16,7 @@ In our particular instance of the game, the target rewards 4 different amounts o
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 at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0).

Write a function that given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), returns the correct amount earned by a dart landing at that point.
Given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), calculate the correct score earned by a dart landing at that point.

## Credit

Expand Down
3 changes: 2 additions & 1 deletion exercises/practice/darts/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"macta"
],
"contributors": [
"bencoman"
"bencoman",
"bajger"
],
"files": {
"solution": [
Expand Down
1 change: 1 addition & 0 deletions exercises/practice/darts/.meta/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Pythagorean theorem will help.
9 changes: 5 additions & 4 deletions exercises/practice/darts/.meta/solution/Darts.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
This is pretty straight forward if the soluton uses c = sqrt of a^2 + b^2
"
Class {
#name : #Darts,
#superclass : #Object,
#category : #'Exercise@Darts'
#name : 'Darts',
#superclass : 'Object',
#category : 'Exercise@Darts',
#package : 'Exercise@Darts'
}

{ #category : #scoring }
{ #category : 'scoring' }
Darts >> scoreX: anInteger y: anotherInteger [
| length |

Expand Down
17 changes: 12 additions & 5 deletions exercises/practice/darts/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[9033f731-0a3a-4d9c-b1c0-34a1c8362afb]
description = "Missed target"
Expand All @@ -15,10 +22,10 @@ description = "On the middle circle"
description = "On the inner circle"

[1c5ffd9f-ea66-462f-9f06-a1303de5a226]
description = "Exactly on centre"
description = "Exactly on center"

[b65abce3-a679-4550-8115-4b74bda06088]
description = "Near the centre"
description = "Near the center"

[66c29c1d-44f5-40cf-9927-e09a1305b399]
description = "Just within the inner circle"
Expand Down
Loading

0 comments on commit d906135

Please sign in to comment.