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

Awk triangle #233

Merged
merged 4 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awk/.package-name_test.awk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/gawk --lint --file
#!/usr/bin/gawk --bignum --lint --file

@include "awkunit"
@include "test-cases"
Expand Down
1 change: 1 addition & 0 deletions awk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
- [leap](./leap/README.md)
- [armstrong-numbers](./armstrong-numbers/README.md)
- [grains](./grains/README.md)
- [triangle](./triangle/README.md)
19 changes: 19 additions & 0 deletions awk/triangle/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"IsaacG"
],
"files": {
"solution": [
"triangle.awk"
],
"test": [
"test-triangle.bats"
],
"example": [
".meta/example.awk"
]
},
"blurb": "Determine if a triangle is equilateral, isosceles, or scalene.",
"source": "The Ruby Koans triangle project, parts 1 & 2",
"source_url": "https://web.archive.org/web/20220831105330/http://rubykoans.com"
}
1 change: 1 addition & 0 deletions awk/triangle/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"awk","exercise":"triangle","id":"398f063987f84b3ca8834ac137467208","url":"https://exercism.org/tracks/awk/exercises/triangle","handle":"vpayno","is_requester":true,"auto_approve":false}
1 change: 1 addition & 0 deletions awk/triangle/.lint_default_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-v type=equilateral
1 change: 1 addition & 0 deletions awk/triangle/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[error]: not a triangle [7 3 2]
99 changes: 99 additions & 0 deletions awk/triangle/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Help

## Running the tests

Each exercise contains a test file.
Run the tests using the `bats` program.
```bash
bats test-hello-world.bats
```

`bats` will need to be installed.
See the [Testing on the Bash track][bash] page for instructions to install `bats` for your system.

### bats is implemented in bash

The bats file is a bash script, with some special functions recognized by the `bats` command.
You'll see some tests that look like
```sh
gawk -f some-exercise.awk <<< "some,input,here"
```
That `<<<` syntax is a bash [Here String][here-string].
It sends the string on the right-hand side into the standard input of the program on the left-hand side.
It is ([approximately][so]) the same as
```sh
echo "some,input,here" | gawk -f some-exercise.awk
```

## Help for assert functions

The tests use functions from the [bats-assert][bats-assert] library.
Help for the various `assert*` functions can be found there.

## Skipped tests

Solving an exercise means making all its tests pass.
By default, only one test (the first one) is executed when you run the tests.
This is intentional, as it allows you to focus on just making that one test pass.
Once it passes, you can enable the next test by commenting out or removing the

[[ $BATS_RUN_SKIPPED == true ]] || skip

annotations prepending other tests.

## Overriding skips

To run all tests, including the ones with `skip` annotations, you can run:
```bash
BATS_RUN_SKIPPED=true bats test-some-exercise.bats
```

It can be convenient to use a wrapper function to save on typing: in `bash` you can do:
```bash
bats() {
BATS_RUN_SKIPPED=true command bats *.bats
}
```
Then run tests with just:
```bash
bats
```

[bash]: https://exercism.org/docs/tracks/bash/tests
[bats-assert]: https://github.com/bats-core/bats-assert
[here-string]: https://www.gnu.org/software/bash/manual/bash.html#Here-Strings
[so]: https://unix.stackexchange.com/a/80372/4667

## Submitting your solution

You can submit your solution using the `exercism submit triangle.awk` 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 [AWK track's documentation](https://exercism.org/docs/tracks/awk)
- [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.

Places to look for help for AWK questions:

* [Stack Overflow `awk` tag][so].
* check the Resources section of the [Stack Overflow `awk` tag into page][so-info].
* raise an issue at the [exercism/awk][github] Github repository.
* IRC: `irc://irc.liberachat.net/#awk`, `irc://irc.liberachat.net/#exercism`
* see [Libera.chat][libera] if you're unfamiliar with IRC.


[so]: https://stackoverflow.com/tags/awk
[so-info]: https://stackoverflow.com/tags/awk/info
[github]: https://github.com/exercism/awk
[libera]: https://libera.chat
51 changes: 51 additions & 0 deletions awk/triangle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Triangle

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

## Instructions

Determine if a triangle is equilateral, isosceles, or scalene.

An _equilateral_ triangle has all three sides the same length.

An _isosceles_ triangle has at least two sides the same length.
(It is sometimes specified as having exactly two sides the same length, but for the purposes of this exercise we'll say at least two.)

A _scalene_ triangle has all sides of different lengths.

## Note

For a shape to be a triangle at all, all sides have to be of length > 0, and the sum of the lengths of any two sides must be greater than or equal to the length of the third side.

In equations:

Let `a`, `b`, and `c` be sides of the triangle.
Then all three of the following expressions must be true:

```text
a + b ≥ c
b + c ≥ a
a + c ≥ b
```

See [Triangle Inequality][triangle-inequality]

[triangle-inequality]: https://en.wikipedia.org/wiki/Triangle_inequality

## Source

### Created by

- @IsaacG

### Based on

The Ruby Koans triangle project, parts 1 & 2 - https://web.archive.org/web/20220831105330/http://rubykoans.com

### My Solution

- [my solution](./triangle.awk)
- [awkunit tests](./triangle_test.awk)
- [test cases](./test-cases.awk)
- [run-tests](./run-tests-awk.txt)
1 change: 1 addition & 0 deletions awk/triangle/awkunit.awk
Loading