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

Dart luhn #226

Merged
merged 6 commits into from
Sep 2, 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: 2 additions & 0 deletions .github/citools/awk/awk-bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare -i retval=0

export BATS_RUN_SKIPPED=true

for tf in ./*.bats; do
echo Running: bats "${tf}"
time bats "${tf}" || ((retval++))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Exercism Workspace
| June | Summer-of-Sexps | Common-Lisp (5/5) |
| July | Jurassic | C (5/5), C++ (5/5), Fortran (0/5) |
| August | Apps | Dart (5/5), Java (0/5), Kotlin (0/5) |
| September | Slimline | Awk (2/5), Bash\* (5/5), jq (0/5), Perl (0/5) |
| September | Slimline | Awk (3/5), Bash\* (5/5), jq (0/5), Perl (0/5) |
| October | Object-Oriented | |
| November | Nibbly | |
| December | Diversions | |
Expand Down
1 change: 1 addition & 0 deletions awk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- [reverse-string](./reverse-string/README.md)
- [gigasecond](./gigasecond/README.md)
- [darts](./darts/README.md)
- [luhn](./luhn/README.md)
54 changes: 27 additions & 27 deletions awk/darts/run-tests-awk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ gawk: warning: function `assertEquals' defined but never called directly
gawk: warning: function `assert' defined but never called directly
gawk: ./awkunit.awk:26: warning: reference to uninitialized variable `_assert_exit'

real 0m0.003s
user 0m0.003s
sys 0m0.000s
real 0m0.006s
user 0m0.002s
sys 0m0.004s

gawk --lint --file=./darts.awk < /dev/null > /dev/null

Expand All @@ -27,8 +27,8 @@ sys 0m0.001s
gawk --lint --file=./test-cases.awk < /dev/null > /dev/null

real 0m0.004s
user 0m0.001s
sys 0m0.003s
user 0m0.003s
sys 0m0.001s

exit 0

Expand All @@ -37,22 +37,22 @@ exit 0
Running: bats ./test-darts.bats
1..13
ok 1 Missed target
ok 2 On the outer circle # skip
ok 3 On the middle circle # skip
ok 4 On the inner circle # skip
ok 5 Exactly on centre # skip
ok 6 Near the centre # skip
ok 7 Just within the inner circle # skip
ok 8 Just outside the inner circle # skip
ok 9 Just within the middle circle # skip
ok 10 Just outside the middle circle # skip
ok 11 Just within the outer circle # skip
ok 12 Just outside the outer circle # skip
ok 13 Asymmetric position between the inner and middle circles # skip

real 0m0.448s
user 0m0.270s
sys 0m0.202s
ok 2 On the outer circle
ok 3 On the middle circle
ok 4 On the inner circle
ok 5 Exactly on centre
ok 6 Near the centre
ok 7 Just within the inner circle
ok 8 Just outside the inner circle
ok 9 Just within the middle circle
ok 10 Just outside the middle circle
ok 11 Just within the outer circle
ok 12 Just outside the outer circle
ok 13 Asymmetric position between the inner and middle circles

real 0m0.546s
user 0m0.361s
sys 0m0.213s

exit 0

Expand Down Expand Up @@ -162,9 +162,9 @@ Test 18:

18 out of 18 tests passed!

real 0m0.008s
user 0m0.002s
sys 0m0.006s
real 0m0.007s
user 0m0.005s
sys 0m0.003s

Tests Passed!

Expand All @@ -174,9 +174,9 @@ exit 0

Running: misspell .

real 0m0.039s
user 0m0.045s
sys 0m0.014s
real 0m0.028s
user 0m0.026s
sys 0m0.017s

===============================================================================

36 changes: 18 additions & 18 deletions awk/gigasecond/run-tests-awk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ gawk: warning: function `assertEquals' defined but never called directly
gawk: warning: function `assert' defined but never called directly
gawk: ./awkunit.awk:26: warning: reference to uninitialized variable `_assert_exit'

real 0m0.003s
user 0m0.002s
sys 0m0.001s
real 0m0.004s
user 0m0.000s
sys 0m0.003s

gawk --lint --file=./gigasecond.awk < /dev/null > /dev/null
gawk: ./gigasecond.awk:21: warning: `mktime' is a gawk extension
gawk: ./gigasecond.awk:25: warning: `strftime' is a gawk extension

real 0m0.004s
real 0m0.005s
user 0m0.001s
sys 0m0.003s

gawk --lint --file=./test-cases.awk < /dev/null > /dev/null

real 0m0.003s
user 0m0.003s
sys 0m0.000s
user 0m0.001s
sys 0m0.002s

exit 0

Expand All @@ -39,14 +39,14 @@ exit 0
Running: bats ./test-gigasecond.bats
1..5
ok 1 date only specificaion of time
ok 2 second test for date only specification of time # skip
ok 3 third test for date only specification of time # skip
ok 4 full time specified # skip
ok 5 full time with day roll-over # skip
ok 2 second test for date only specification of time
ok 3 third test for date only specification of time
ok 4 full time specified
ok 5 full time with day roll-over

real 0m0.226s
user 0m0.136s
sys 0m0.108s
real 0m0.216s
user 0m0.145s
sys 0m0.086s

exit 0

Expand Down Expand Up @@ -101,9 +101,9 @@ Test 7:

7 out of 7 tests passed!

real 0m0.003s
real 0m0.008s
user 0m0.002s
sys 0m0.002s
sys 0m0.006s

Tests Passed!

Expand All @@ -113,9 +113,9 @@ exit 0

Running: misspell .

real 0m0.025s
user 0m0.030s
sys 0m0.010s
real 0m0.036s
user 0m0.042s
sys 0m0.013s

===============================================================================

30 changes: 15 additions & 15 deletions awk/hello-world/run-tests-awk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ gawk: warning: function `assertEquals' defined but never called directly
gawk: warning: function `assert' defined but never called directly
gawk: ./awkunit.awk:26: warning: reference to uninitialized variable `_assert_exit'

real 0m0.002s
user 0m0.001s
sys 0m0.001s
real 0m0.003s
user 0m0.002s
sys 0m0.000s

gawk --lint --file=./hello-world.awk < /dev/null > /dev/null

real 0m0.002s
user 0m0.001s
sys 0m0.001s
user 0m0.002s
sys 0m0.000s

gawk --lint --file=./test-cases.awk < /dev/null > /dev/null
gawk: ./test-cases.awk:10: warning: subscript of array `cases' is null string

real 0m0.002s
user 0m0.000s
sys 0m0.002s
user 0m0.001s
sys 0m0.001s

exit 0

Expand All @@ -39,9 +39,9 @@ Running: bats ./test-hello-world.bats
1..1
ok 1 Say Hi!

real 0m0.084s
user 0m0.050s
sys 0m0.049s
real 0m0.112s
user 0m0.071s
sys 0m0.059s

exit 0

Expand All @@ -67,8 +67,8 @@ Test 1:
1 out of 2 tests passed!

real 0m0.005s
user 0m0.002s
sys 0m0.003s
user 0m0.003s
sys 0m0.002s

Tests Passed!

Expand All @@ -78,9 +78,9 @@ exit 0

Running: misspell .

real 0m0.035s
user 0m0.036s
sys 0m0.013s
real 0m0.025s
user 0m0.027s
sys 0m0.011s

===============================================================================

19 changes: 19 additions & 0 deletions awk/luhn/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"glennj"
],
"files": {
"solution": [
"luhn.awk"
],
"test": [
"test-luhn.bats"
],
"example": [
".meta/example.awk"
]
},
"blurb": "Given a number determine whether or not it is valid per the Luhn formula.",
"source": "The Luhn Algorithm on Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Luhn_algorithm"
}
1 change: 1 addition & 0 deletions awk/luhn/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"awk","exercise":"luhn","id":"09b7d064ae9e4eb6a98b19e7e5d7d222","url":"https://exercism.org/tracks/awk/exercises/luhn","handle":"vpayno","is_requester":true,"auto_approve":false}
99 changes: 99 additions & 0 deletions awk/luhn/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 luhn.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
Loading