Skip to content

Commit a41c196

Browse files
authored
Use MiBytes to one d.p. (#65)
* Use MiBytes to one d.p. * Right align lines, time, memory * Functional tests * Functional tests * Unit tests * Functional tests * Functional tests * Functional tests
1 parent 9170b06 commit a41c196

File tree

10 files changed

+49
-49
lines changed

10 files changed

+49
-49
lines changed

.github/workflows/functional_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
sed -i -E 's/[0-9]+\.[0-9]+/x/' tests/README.md
3737
sed -i -E 's/[0-9]+/y/' tests/README.md
3838
sed -i -E 's/[0-9]+/a/' tests/README.md
39-
sed -i -E 's/[0-9]+/z/' tests/README.md
39+
sed -i -E 's/[0-9]+\.[0-9]+/z/' tests/README.md
4040
diff --ignore-all-space --ignore-blank-lines tests/README.md tests/EXPECTED_README.md
4141
test_with_explicit_inputs:
4242
runs-on: ubuntu-latest
@@ -73,5 +73,5 @@ jobs:
7373
sed -i -E 's/[0-9]+\.[0-9]+/x/' tests/README.md
7474
sed -i -E 's/[0-9]+/y/' tests/README.md
7575
sed -i -E 's/[0-9]+/a/' tests/README.md
76-
sed -i -E 's/[0-9]+/z/' tests/README.md
76+
sed -i -E 's/[0-9]+\.[0-9]+/z/' tests/README.md
7777
diff --ignore-all-space --ignore-blank-lines tests/README.md tests/EXPECTED_README_4.md

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
If you and your friends/colleagues share a repo for [Advent of Code](https://adventofcode.com), you can use this to run and compare your solutions to each day's problems.
66
It will time each person's solution, monitor maximum memory usage and count the lines of code, saving the results to the README:
77

8-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
9-
| --- | --- | --- | --- | --- | --- | --- | --- |
8+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
9+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
1010
| 01 | python | tim | 15 | one | 0.00 | 9728 | |
1111
| 01 | python | tim | 15 | two | 0.02 | 9856 | |
1212

advent_of_action/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
type Language = str
2929
type Person = str
3030
type Seconds = str
31-
type Kilobytes = str
31+
type MiBytes = str
3232
type Notes = str
3333
type Run = tuple[Day, Language, Person]
34-
type Stat = tuple[Seconds, Kilobytes, Notes]
34+
type Stat = tuple[Seconds, MiBytes, Notes]
3535
type linecount = int
3636
type Stats = tuple[Stat, Stat, linecount]
3737

@@ -43,12 +43,12 @@ def inner(part: Part, answer: str | None, command: list[str | Path]) -> Stat:
4343
"""Use the runner to measure the execution time of one part."""
4444
try:
4545
if answer is not None:
46-
kilobytes, seconds, output = execute_command(command, part=part)
46+
kibytes, seconds, output = execute_command(command, part=part)
4747
if output != answer:
4848
print(f"Incorrect answer for part {part}: {output}")
4949
return "", "", "Different answer"
5050
else:
51-
return f"{seconds:.2f}", f"{kilobytes}", ""
51+
return f"{seconds:.2f}", f"{kibytes / 1024.0:.1f}", ""
5252
else:
5353
# Ignore empty lists.
5454
if command:
@@ -98,8 +98,8 @@ def from_table(table: str) -> dict[Run, Stats]:
9898
def to_table(results: Mapping[Run, Stats]) -> str:
9999
"""Convert results to a Markdown table."""
100100
table = "\n\n## Stats\n\n"
101-
table += "| day | language | who | lines | part | time (s) | mem (KiB) | notes |\n"
102-
table += "| --- | --- | --- | --- | --- | --- | --- | --- |\n"
101+
table += "| day | language | who | lines | part | time (s) | mem (MiB) | notes |\n"
102+
table += "| --- | --- | --- | ---: | --- | ---: | ---: | --- |\n"
103103
for the_run, stats in results.items():
104104
day, language, person = the_run
105105
for (seconds, kilobytes, notes), part in zip(stats[:2], (Part.ONE, Part.TWO), strict=False):

tests/EXPECTED_README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ A sentence.
44

55
## Stats
66

7-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
8-
| --- | --- | --- | --- | --- | --- | --- | --- |
7+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
8+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
99
| y | python | iain | a | one | x | z | |
1010
| y | python | iain | a | two | x | z | |
1111
| y | fsharp | iain | a | one | x | z | |
@@ -20,8 +20,8 @@ A sentence.
2020
| y | ocaml | iain | a | two | | | Different answer |
2121
| y | python | iain | a | one | x | z | |
2222
| y | python | iain | a | two | x | z | |
23-
| y | python | zain | a | one | | | Error(z) |
24-
| y | python | zain | a | two | | | Error(z) |
23+
| y | python | zain | a | one | | | Error(1) |
24+
| y | python | zain | a | two | | | Error(1) |
2525
| y | racket | iain | a | one | x | z | |
2626
| y | racket | iain | a | two | | | Different answer |
2727
| y | rust | iain | a | one | x | z | |

tests/EXPECTED_README_2.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ A sentence.
44

55
## Stats
66

7-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
8-
| --- | --- | --- | --- | --- | --- | --- | --- |
9-
| 00 | python | iain | 3 | one | 2.34 | 1999 | |
10-
| 00 | python | iain | 3 | two | 2.34 | 1999 | |
11-
| 01 | python | iain | 3 | one | 0.01 | 1792 | |
12-
| 01 | python | iain | 3 | two | 0.01 | 1792 | |
7+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
8+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
9+
| 00 | python | iain | 3 | one | 2.34 | 19.0 | |
10+
| 00 | python | iain | 3 | two | 2.34 | 19.0 | |
11+
| 01 | python | iain | 3 | one | 0.01 | 17.0 | |
12+
| 01 | python | iain | 3 | two | 0.01 | 17.0 | |
1313

1414

1515
## Section

tests/EXPECTED_README_3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A sentence.
55

66
## Stats
77

8-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
9-
| --- | --- | --- | --- | --- | --- | --- | --- |
8+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
9+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
1010
| 01 | python | iain | 8 | one | 0.01 | 1792 | |
1111
| 01 | python | iain | 8 | two | 0.01 | 1792 | |

tests/EXPECTED_README_4.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ A sentence.
44

55
## Stats
66

7-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
8-
| --- | --- | --- | --- | --- | --- | --- | --- |
7+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
8+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
99
| y | python | iain | a | one | x | z | |
1010
| y | python | iain | a | two | x | z | |
1111
| y | fsharp | iain | a | one | x | z | |
@@ -16,14 +16,14 @@ A sentence.
1616
| y | haskell | iain | a | two | | | Different answer |
1717
| y | jupyter | iain | a | one | x | z | |
1818
| y | jupyter | iain | a | two | | | Different answer |
19-
| y | ocaml | iain | a | one | | | Error(z) |
20-
| y | ocaml | iain | a | two | | | Error(z) |
19+
| y | ocaml | iain | a | one | | | Error(127) |
20+
| y | ocaml | iain | a | two | | | Error(127) |
2121
| y | python | iain | a | one | x | z | |
2222
| y | python | iain | a | two | x | z | |
23-
| y | python | zain | a | one | | | Error(z) |
24-
| y | python | zain | a | two | | | Error(z) |
25-
| y | racket | iain | a | one | | | Error(z) |
26-
| y | racket | iain | a | two | | | Error(z) |
23+
| y | python | zain | a | one | | | Error(1) |
24+
| y | python | zain | a | two | | | Error(1) |
25+
| y | racket | iain | a | one | | | Error(127) |
26+
| y | racket | iain | a | two | | | Error(127) |
2727
| y | rust | iain | a | one | x | z | |
2828
| y | rust | iain | a | two | | | Different answer |
2929

tests/README_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ A sentence.
55
## Stats
66

77
| day | language | who | lines | part | time | mem | notes |
8-
| --- | --- | --- | --- | --- | --- | --- | --- |
9-
| 00 | python | iain | 3 | one | 2.34 | 1999 | |
10-
| 00 | python | iain | 3 | two | 2.34 | 1999 | |
8+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
9+
| 00 | python | iain | 3 | one | 2.34 | 19.0 | |
10+
| 00 | python | iain | 3 | two | 2.34 | 19.0 | |
1111

1212
## Section
1313

tests/README_TEMPLATE_3.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ A sentence.
44

55
## Stats
66

7-
| day | language | who | lines | part | time (s) | mem (KiB) | notes |
8-
| --- | --- | --- | --- | --- | --- | --- | --- |
9-
| 99 | go | iain | 8 | one | 1 | 8 | |
7+
| day | language | who | lines | part | time (s) | mem (MiB) | notes |
8+
| --- | --- | --- | ---: | --- | ---: | ---: | --- |
9+
| 99 | go | iain | 8 | one | 1 | 8.0 | |
1010
| 99 | go | iain | 8 | two | | | Different answer |
11-
| 99 | haskell | iain | 8 | one | 1 | 8 | |
11+
| 99 | haskell | iain | 8 | one | 1 | 8.0 | |
1212
| 99 | haskell | iain | 8 | two | | | Different answer |
13-
| 99 | jupyter | iain | 8 | one | 1 | 8 | |
13+
| 99 | jupyter | iain | 8 | one | 1 | 8.0 | |
1414
| 99 | jupyter | iain | 8 | two | | | Different answer |
15-
| 99 | ocaml | iain | 8 | one | 1 | 8 | |
15+
| 99 | ocaml | iain | 8 | one | 1 | 8.0 | |
1616
| 99 | ocaml | iain | 8 | two | | | Different answer |
17-
| 99 | python | iain | 8 | one | 1 | 8 | |
18-
| 99 | python | iain | 8 | two | 1 | 8 | |
17+
| 99 | python | iain | 8 | one | 1 | 8.0 | |
18+
| 99 | python | iain | 8 | two | 1 | 8.0 | |
1919
| 99 | python | zain | 8 | one | | | Error(z) |
2020
| 99 | python | zain | 8 | two | | | Error(z) |
21-
| 99 | racket | iain | 8 | one | 1 | 8 | |
21+
| 99 | racket | iain | 8 | one | 1 | 8.0 | |
2222
| 99 | racket | iain | 8 | two | | | Different answer |
23-
| 99 | rust | iain | 8 | one | 1 | 8 | |
23+
| 99 | rust | iain | 8 | one | 1 | 8.0 | |
2424

2525

2626
## Section

tests/test_main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_measure_one(self, mock_run: MagicMock) -> None:
206206
mock_run.return_value = MagicMock(stdout="answer\n", stderr="1792,0.02,0.01")
207207

208208
actual = main.measure_execution_time(("answer", "answer"), Commands([], [], []))
209-
expected = ("0.03", "1792", ""), ("0.03", "1792", "")
209+
expected = (("0.03", "1.8", ""),) * 2
210210
self.assertEqual(
211211
expected,
212212
actual,
@@ -286,7 +286,7 @@ def test_write_results(self) -> None:
286286
expected_readme_txt = Path("EXPECTED_README_2.md").read_text()
287287

288288
run = ("01", "python", "iain")
289-
stat = ("0.01", "1792", "")
289+
stat = ("0.01", "17.0", "")
290290

291291
main.write_results({run: (stat, stat, 3)})
292292
self.assertEqual(expected_readme_txt, readme.read_text())
@@ -321,8 +321,8 @@ def test_from_table(self) -> None:
321321
+ "\n"
322322
+ "## Stats\n"
323323
+ "\n"
324-
+ "| day | language | who | lines | part | time (s) | mem (KiB) | notes |\n"
325-
+ "| --- | --- | --- | --- | --- | --- | --- | --- |\n"
324+
+ "| day | language | who | lines | part | time (s) | mem (MiB) | notes |\n"
325+
+ "| --- | --- | --- | ---: | --- | ---: | ---: | --- |\n"
326326
+ "| 01 | python | iain | 7 | one | 0.01 | 1792 | |\n"
327327
+ "| 01 | python | iain | 7 | two | 0.01 | 1792 | |\n"
328328
+ "\n"
@@ -339,8 +339,8 @@ def test_from_table_raises(self) -> None:
339339
+ "\n"
340340
+ "## Stats\n"
341341
+ "\n"
342-
+ "| day | language | who | lines | part | time (s) | mem (KiB) | notes |\n"
343-
+ "| --- | --- | --- | --- | --- | --- | --- | --- |\n"
342+
+ "| day | language | who | lines | part | time (s) | mem (MiB) | notes |\n"
343+
+ "| --- | --- | --- | ---: | --- | ---: | ---: | --- |\n"
344344
+ "| 01 | python | iain | 7 | three | 0.01 | 1792 | |\n"
345345
+ "\n"
346346
+ "\n"

0 commit comments

Comments
 (0)