Skip to content

Commit b4edd34

Browse files
authored
Refactor / Enable multiple input/output-pairs per day ++ (#72)
* Support testing against multiple input/output pairs * solve day09 in deno * rewrite day09 -> day25 * refac lang/ - reuse time start and stop * update CONTRIBUTING.md * Add test.sh at root-level * add lib/-folder at root-level
1 parent 3b0544e commit b4edd34

File tree

135 files changed

+659
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+659
-481
lines changed

.github/workflows/day-00-example.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ on:
55
- main
66
paths:
77
- 'days/day-00-example/**'
8-
- 'languages/**'
8+
- 'lang/**'
99
- 'Makefile'
1010
pull_request:
1111
branches:
1212
- main
1313
paths:
1414
- 'days/day-00-example/**'
15-
- 'languages/**'
15+
- 'lang/**'
1616
- 'Makefile'
1717
workflow_dispatch:
1818

CONTRIBUTING.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,53 @@
44

55
1. Pop some popcorn :popcorn: (or whatever you enjoy :lollipop: :champagne: :milk_glass: :wine_glass: :tropical_drink: :chocolate_bar: :beer:)
66
2. Fork
7-
3. Write a solution, in the language of your choice. Example: `vim day-03/solutions/super-optimized.py`
8-
4. Test your solution.
7+
3. Write a solution, in the language of your choice. Example: `vim days/day-03/solutions/super-optimized.py`
8+
4. Test your solution
99

1010
```sh
11-
cd days/day03
12-
../../languages/python.sh input.txt output.txt solutions/super-optimized.py
11+
$ ./lang/python.sh "days/day-03/solutions/super-optimized.py" "days/day-03/io/my.input days/day-03/io/my.output"
12+
13+
# ..or use the short-hand
14+
$ ./lang/python.sh "days/day-03/**/*.py" "days/day-03/io/*"
15+
16+
cat INPUT | python3 day03.klyve.py 13ms ✅
17+
cat INPUT | python3 day03.preng.py 11ms ✅
18+
cat INPUT | python3 one-liner.py 12ms ✅
1319
```
1420

15-
5. Add the test to `day03/test.sh`, to let the CI know how to test your solution.
16-
6. Make a Pull Request to the `main` branch.
17-
7. One of the maintainers will merge when the tests pass!
18-
8. Remember to have fun :tada:
21+
5. Make sure `days/day03/test.sh` tests your solution.
22+
23+
6. To test the whole day do:
24+
```sh
25+
./days/day03/test.sh
26+
# or
27+
make test.day03
28+
# or
29+
make docker.day03
30+
```
31+
32+
7. When you are happy with local testing, make a Pull Request to the `main` branch.
33+
8. One of the maintainers will merge PR's, at the of each day.
34+
9. Remember to have fun :tada:
1935

2036

2137
## How do I add a language?
2238

2339
1. Add the language you want to the `Dockerfile`
24-
2. Add a language test-script in `languages/<new-language>.sh`
40+
2. Add a language test-script in `lang/<new-language>.sh`
2541
3. Add an example solution in `days/day-00-example/solutions/example.<new-language>`
2642
4. Make a PR to `main`-branch.
27-
5. One of the maintainers will do `make docker.build` and `make docker.push` and merge your PR on his machine ASAP :racing_car:
43+
5. One of the maintainers will push a new docker-image to dockerhub.com, based on your PR.
44+
6. ...then make sure Github workflows uses the new docker-image.
45+
7. ...then merge the PR.
2846

2947
## How are solutions tested?
3048

31-
Every solution gets the `input.txt`-file delivered to `stdin` using `cat`, and whatever is written to `stdout` is compared for equality against `output.txt` using `diff`. This is identical for every language.
49+
Every solution gets the `io/*.input`-files for a given day delivered to `stdin`, using `cat`. Whatever is written to `stdout` by the solution, is then compared for equality against `io/*.output`-files, using `diff`. This is identical for every language.
3250

3351
```sh
3452
#!/usr/bin/env bash
35-
cat input.txt | <solution-in-any-language> | diff - output.txt
53+
cat day-03/io/my.input | <solution-in-any-language> | diff - day-03/io/my.output
3654
```
55+
3756
See [day-00-example/solutions/](https://github.com/Arxcis/adventofcode2020/tree/main/days/day-00-example/solutions), for examples on how to read from `stdin` and how to write to `stdout` in different languages.

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export DOCKER_TAG="jonasjso/adventofcode2020:2020-12-07-with-deno"
1414
;\
1515

1616
test.all:
17-
for day in $$(ls days); do ./days/$$day/test.sh; done
17+
./test.sh
1818

1919
test.versions:
2020
./scripts/print-versions.sh
@@ -131,6 +131,8 @@ docker.day07:
131131
make docker.test DAY=day-07
132132
docker.day08:
133133
make docker.test DAY=day-08
134+
docker.day09:
135+
make docker.test DAY=day-09
134136
docker.day10:
135137
make docker.test DAY=day-10
136138
docker.day11:

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ Welcome to this community project, where we collaboratively solve the 2020 editi
55

66
## Solutions per language per day
77

8-
| Language | Total | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|
9-
|-----------|--------|------|-----|-----|------|-----|-----|-----|-----|----|----|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
10-
| python3 | **18** | 2 | 1 | 3 | 4 | 4 | 3 | 1 | | | ||||||||||||||||
11-
| golang | **13** | 2 | 2 | 2 | 1 | 2 | 2 | 1 | 1 | | ||||||||||||||||
12-
| sml | **8** | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | ||||||||||||||||
13-
| deno.ts | **8** | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | ||||||||||||||||
14-
| c | **6** | 1 | 1 | 1 | 1 | 1 | 1 | | | | ||||||||||||||||
15-
| zig | **5** | 1 | 1 | 1 | 1 | 1 | | | | | ||||||||||||||||
16-
| node.js | **4** | 1 | | | 1 | | 1 | 1 | | | ||||||||||||||||
17-
| c++ | **2** | 1 | 1 | | | | | | | | ||||||||||||||||
18-
| ruby | **2** | 1 | | | 1 | | | | | | ||||||||||||||||
19-
| rust | **1** | 1 | | | | | | | | | ||||||||||||||||
20-
| bash | **0** | | | | | | | | | | ||||||||||||||||
21-
| java | **0** | | | | | | | | | | ||||||||||||||||
22-
| php | **0** | | | | | | | | | | ||||||||||||||||
23-
| **Total** | **65** |**12**|**8**|**9**|**10**|**9**|**9**|**5**|**3**| | ||||||||||||||||
24-
25-
*Last updated: 2020-12-09 18:56:00Z*
8+
| Language | Total | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|
9+
|-----------|--------|------|-----|-----|------|------|-----|-----|-----|-----|----|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
10+
| python3 | **18** | 2 | 1 | 3 | 4 | 4 | 3 | 1 | | | ||||||||||||||||
11+
| golang | **13** | 2 | 2 | 2 | 1 | 2 | 2 | 1 | 1 | | ||||||||||||||||
12+
| sml | **8** | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | ||||||||||||||||
13+
| deno.ts | **8** | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||||||
14+
| c | **6** | 1 | 1 | 1 | 1 | 1 | 1 | | | | ||||||||||||||||
15+
| zig | **5** | 1 | 1 | 1 | 1 | 1 | | | | | ||||||||||||||||
16+
| node.js | **4** | 1 | | | 1 | | 1 | 1 | | | ||||||||||||||||
17+
| c++ | **2** | 1 | 1 | | | | | | | | ||||||||||||||||
18+
| ruby | **2** | 1 | | | 1 | | | | | | ||||||||||||||||
19+
| rust | **1** | 1 | | | | | | | | | ||||||||||||||||
20+
| bash | **0** | | | | | | | | | | ||||||||||||||||
21+
| java | **0** | | | | | | | | | | ||||||||||||||||
22+
| php | **0** | | | | | | | | | | ||||||||||||||||
23+
| **Total** | **68** |**12**|**8**|**9**|**11**|**10**|**9**|**5**|**3**|**1**| ||||||||||||||||
24+
25+
*Last updated: 2020-12-09 21:30:00Z*
2626

2727
See all languages we support in our [Dockerfile](./Dockerfile).
2828

@@ -85,12 +85,11 @@ If you enjoy working on this project, consider sharing it with your friends. The
8585

8686
## Getting started
8787

88-
### Test a single solution
88+
### Test individual solutions
8989

9090
```
91-
$ cd days/day01
92-
$ ../../languages/rust.sh input.txt output.txt solutions/day01.rs
93-
cat INPUT | rustc day-01/solutions/day01.rs ✅
91+
$ ./lang/rust.sh "days/day-01/solutions/day01.rs" "days/day-01/io/*"
92+
cat INPUT | rustc day01.rs 662ms ✅
9493
```
9594

9695
### Test one or more days

days/day-00-example/io/bob.input

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1
2+
2
3+
3
4+
4
5+
8
6+
12
7+
3000
8+
28731

days/day-00-example/io/bob.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
31761
2+
28735

days/day-00-example/test.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ D=$(dirname $(realpath $0))
55

66
echo ""
77
echo "--- Day 0: Examples ---"
8-
$D/../../languages/rust.sh $D/input.txt $D/output.txt $D/solutions/example.rs
9-
$D/../../languages/go.sh $D/input.txt $D/output.txt $D/solutions/example.go
10-
$D/../../languages/c.sh $D/input.txt $D/output.txt $D/solutions/example.c
11-
$D/../../languages/cpp.sh $D/input.txt $D/output.txt $D/solutions/example.cpp
12-
$D/../../languages/sml.sh $D/input.txt $D/output.txt $D/solutions/example.sml
13-
$D/../../languages/bash.sh $D/input.txt $D/output.txt $D/solutions/example.bash
14-
$D/../../languages/php.sh $D/input.txt $D/output.txt $D/solutions/example.php
15-
$D/../../languages/python.sh $D/input.txt $D/output.txt $D/solutions/example.py
16-
$D/../../languages/deno.sh $D/input.txt $D/output.txt $D/solutions/example.ts
17-
$D/../../languages/node.sh $D/input.txt $D/output.txt $D/solutions/example.mjs
18-
$D/../../languages/ruby.sh $D/input.txt $D/output.txt $D/solutions/example.rb
19-
$D/../../languages/java.sh $D/input.txt $D/output.txt $D/solutions Example
8+
9+
$D/../../lang/rust.sh "$D/solutions/*.rs" "$D/io/*"
10+
$D/../../lang/go.sh "$D/solutions/*.go" "$D/io/*"
11+
$D/../../lang/c.sh "$D/solutions/*.c" "$D/io/*"
12+
$D/../../lang/cpp.sh "$D/solutions/*.cpp" "$D/io/*"
13+
$D/../../lang/sml.sh "$D/solutions/*.sml" "$D/io/*"
14+
$D/../../lang/bash.sh "$D/solutions/*.bash" "$D/io/*"
15+
$D/../../lang/python.sh "$D/solutions/*.py" "$D/io/*"
16+
$D/../../lang/deno.sh "$D/solutions/*.ts" "$D/io/*"
17+
$D/../../lang/node.sh "$D/solutions/*.mjs" "$D/io/*"
18+
$D/../../lang/ruby.sh "$D/solutions/*.rb" "$D/io/*"
19+
$D/../../lang/php.sh "$D/solutions/*.php" "$D/io/*"
20+
2021
echo ""

0 commit comments

Comments
 (0)