Skip to content

Commit

Permalink
mostly arturo
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Leach committed Dec 16, 2024
1 parent 83542ee commit 85c4e6f
Show file tree
Hide file tree
Showing 29 changed files with 1,973 additions and 0 deletions.
175 changes: 175 additions & 0 deletions arturo/darts/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Help

## Running the tests

This track uses the [Unitt unit-testing package][unitt], installed automatically when running the tests.
From within the exercise folder, run `exercism test` or `arturo tester.art` to run your solution against the test suite.

If you haven't written any code, the test suite will fail with a message like:

```plaintext
===== tests\test-leap.art =====
Suite: Leap
══╡ Program Error ╞═════════════════════════════════════════════════ <script> ══
please implement the isLeap? function
===== Statistics =====
⏏️ TOTAL: 0 assertions
✅ PASSED: 0 assertions
⏩ SKIPPED: 0 assertions
❌ FAILED: 0 assertions
===== ========== =====
```

Replace the `panic "please implement the <some-function-name> function"` line in `src\<your-exercise>.art` with your solution.
Then rerun the test suite, and you should see something like:

```plaintext
===== tests\test-leap.art =====
Suite: Leap
✅ - assert that a year not divisible by 4 is a common year
assertion: false = false
⏩ - assert that a year divisible by 2 and not divisible by 4 is a common year
skipped!
⏩ - assert that a year divisible by 4 and not divisible by 100 is a leap year
skipped!
===== Statistics =====
⏏️ TOTAL: 1 assertions
✅ PASSED: 1 assertions
⏩ SKIPPED: 2 assertions
❌ FAILED: 0 assertions
===== ========== =====
```

The output lists the test file path, the name of the test suite, and the test case assertions, reporting whether a test had passed (✅), failed (❌) or was skipped (⏩).

The following test file has three tests, one of which is skipped.
Unskip a test by replacing `test.skip` with `test` beside the description for the test.

```arturo
import {unitt}!
import {src/leap}!
suite "Leap" [
test "a year not divisible by 4 is a common year" [
result: isLeap? 2015
assert -> false = result
]
test "a year divisible by 2 and not divisible by 4 is a common year" [
result: isLeap? 1970
assert -> false = result
]
test.skip "a year divisible by 4 and not divisible by 100 is a leap year" [
result: isLeap? 1996
assert -> true = result
]
]
```

If we rerun the tests again, the second test is run and passes, but the third test is still skipped.


```plaintext
===== tests\test-leap.art =====
Suite: Leap
✅ - assert that a year not divisible by 4 is a common year
assertion: false = false
✅ - assert that a year divisible by 2 and not divisible by 4 is a common year
assertion: false = false
⏩ - assert that a year divisible by 4 and not divisible by 100 is a leap year
skipped!
===== Statistics =====
⏏️ TOTAL: 2 assertions
✅ PASSED: 2 assertions
⏩ SKIPPED: 1 assertions
❌ FAILED: 0 assertions
===== ========== =====
```

A failed test would look like this

```plaintext
===== tests/test-leap.art =====
Suite: Leap
✅ - assert that a year not divisible by 4 is a common year
assertion: false = false
✅ - assert that a year divisible by 2 and not divisible by 4 is a common year
assertion: false = false
❌ - assert that a year divisible by 4 and not divisible by 100 is a leap year
assertion: true = false
===== Statistics =====
⏏️ TOTAL: 3 assertions
✅ PASSED: 2 assertions
⏩ SKIPPED: 0 assertions
❌ FAILED: 1 assertions
===== ========== =====
```

Once all tests pass, you can submit your solution using `exercism submit`.

[packager]: https://pkgr.art/

## Submitting your solution

You can submit your solution using the `exercism submit src/darts.art` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Arturo track's documentation](https://exercism.org/docs/tracks/arturo)
- The [Arturo track's programming category on the forum](https://forum.exercism.org/c/programming/arturo)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

Here are some resources for getting help if you run into trouble

* [Official Documentation][official-docs] covers syntax, language features, and the standard library modules.
* [Arturo Discord][discord] is Arturo's official Discord server.
* [Rosetta Code][rosetta-code] has over 770+ Arturo code examples for many different tasks.

[official-docs]: https://arturo-lang.io/master/documentation/
[discord]: https://discord.gg/YdVK2CB
[rosetta-code]: https://rosettacode.org/wiki/Category:Arturo
46 changes: 46 additions & 0 deletions arturo/darts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Darts

Welcome to Darts on Exercism's Arturo Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

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].

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

![Our dart scoreboard with values from a complete miss to a bullseye](https://assets.exercism.org/images/exercises/darts/darts-scoreboard.svg)

- 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

## Source

### Created by

- @BNAndras

### Based on

Inspired by an exercise created by a professor Della Paolera in Argentina
7 changes: 7 additions & 0 deletions arturo/darts/src/darts.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
score: function [x y][
r: hypot x y
if r =< 1 -> return 10
if r =< 5 -> return 5
if r =< 10 -> return 1
return 0
]
3 changes: 3 additions & 0 deletions arturo/darts/tester.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {unitt}!

runTests.failFast findTests "tests"
69 changes: 69 additions & 0 deletions arturo/darts/tests/test-darts.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {unitt}!
import {src/darts}!

suite "Darts" [
test "missing target is 0" [
points: score neg 9 9
assert -> 0 = points
]

test "on the outer circle is 1" [
points: score 0 10
assert -> 1 = points
]

test "on the middle circle is 5" [
points: score neg 5 0
assert -> 5 = points
]

test "on the inner circle is 10" [
points: score 0 neg 1
assert -> 10 = points
]

test "exactly on center is 10" [
points: score 0 0
assert -> 10 = points
]

test "near the center is 10" [
points: score neg 0.1 neg 0.1
assert -> 10 = points
]

test "just within the inner circle is 10" [
points: score 0.7 0.7
assert -> 10 = points
]

test "just outside the inner circle is 5" [
points: score 0.8 neg 0.8
assert -> 5 = points
]

test "just within the middle circle is 5" [
points: score neg 3.5 3.5
assert -> 5 = points
]

test "just outside the middle circle is 1" [
points: score neg 3.6 neg 3.6
assert -> 1 = points
]

test "just within the outer circle is 1" [
points: score neg 7.0 7.0
assert -> 1 = points
]

test "just outside the outer circle is 0" [
points: score 7.1 neg 7.1
assert -> 0 = points
]

test "asymmetric positon between the inner and middle circles is 5" [
points: score 0.5 neg 4
assert -> 5 = points
]
]
Loading

0 comments on commit 85c4e6f

Please sign in to comment.