Skip to content

Commit

Permalink
Merge pull request #155 from GriceTurrble/chore/2024-03-py-scaffolded
Browse files Browse the repository at this point in the history
chore: 2024 day 03 python scaffolded
  • Loading branch information
GriceTurrble authored Dec 3, 2024
2 parents f06f043 + 40ed433 commit 3ac7db0
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 20 deletions.
1 change: 1 addition & 0 deletions 2024/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cli = "grice_py_aoc_2024.cli:cli"
day01 = "grice_py_aoc_2024.day01.main:main"
day02 = "grice_py_aoc_2024.day02.main:main"
day03 = "grice_py_aoc_2024.day03.main:main"
day04 = "grice_py_aoc_2024.day04.main:main"

[tool.pytest.ini_options]
addopts = "--verbose"
3 changes: 2 additions & 1 deletion 2024/python/src/grice_py_aoc_2024/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def _create_day_files(day: int) -> None:
day_path.mkdir()
(day_path / "__init__.py").touch()
(day_path / "inputs.txt").touch()
(day_path / "test_inputs.txt").touch()
(day_path / "test_inputs_p1.txt").touch()
(day_path / "test_inputs_p2.txt").touch()
_create_templates(day=day, path=day_path)


Expand Down
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day04/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import time
from pathlib import Path

FILE = Path(__file__).parent / "inputs.txt"


def part1(contents: str):
return "Not done yet!"


def part2(contents: str):
return "Not done yet!"


def main():
contents = FILE.read_text()

_start1 = time.perf_counter()
result1 = part1(contents)
_delta1 = time.perf_counter() - _start1
print(f">> Part 1: {result1} ({_delta1:.6f}s)")

_start2 = time.perf_counter()
result2 = part2(contents)
_delta2 = time.perf_counter() - _start2
print(f">> Part 2: {result2} ({_delta2:.6f}s)")


if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions 2024/python/src/grice_py_aoc_2024/day04/test_day04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from pathlib import Path

from .main import part1, part2

TEST_FILE_P1 = Path(__file__).parent / "test_inputs_p1.txt"
TEST_FILE_P2 = Path(__file__).parent / "test_inputs_p2.txt"
EXPECTED_PART_1 = "Now it's done!"
EXPECTED_PART_2 = "Now it's done!"


def test_part1():
contents = TEST_FILE_P1.read_text()
result = part1(contents)
assert result == EXPECTED_PART_1


def test_part2():
contents = TEST_FILE_P2.read_text()
result = part2(contents)
assert result == EXPECTED_PART_2
Empty file.
Empty file.
16 changes: 6 additions & 10 deletions 2024/python/src/grice_py_aoc_2024/templates/main.py-tpl
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
from __future__ import annotations

import time
import typing
from pathlib import Path

if typing.TYPE_CHECKING:
from io import TextIOWrapper

FILE = Path(__file__).parent / "inputs.txt"


def part1(inputs: TextIOWrapper):
def part1(contents: str):
return "Not done yet!"


def part2(inputs: TextIOWrapper):
def part2(contents: str):
return "Not done yet!"


def main():
contents = FILE.read_text()

_start1 = time.perf_counter()
with open(FILE) as f:
result1 = part1(f)
result1 = part1(contents)
_delta1 = time.perf_counter() - _start1
print(f">> Part 1: {result1} ({_delta1:.6f}s)")

_start2 = time.perf_counter()
with open(FILE) as f:
result2 = part2(f)
result2 = part2(contents)
_delta2 = time.perf_counter() - _start2
print(f">> Part 2: {result2} ({_delta2:.6f}s)")

Expand Down
19 changes: 10 additions & 9 deletions 2024/python/src/grice_py_aoc_2024/templates/test_day.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ from pathlib import Path

from .main import part1, part2

TEST_FILE = Path(__file__).parent / "test_inputs.txt"
RESULT_PART_1 = "Now it's done!"
RESULT_PART_2 = "Now it's done!"
TEST_FILE_P1 = Path(__file__).parent / "test_inputs_p1.txt"
TEST_FILE_P2 = Path(__file__).parent / "test_inputs_p2.txt"
EXPECTED_PART_1 = "Now it's done!"
EXPECTED_PART_2 = "Now it's done!"


def test_part1():
with open(TEST_FILE) as f:
result = part1(f)
assert result == RESULT_PART_1
contents = TEST_FILE_P1.read_text()
result = part1(contents)
assert result == EXPECTED_PART_1


def test_part2():
with open(TEST_FILE) as f:
result = part2(f)
assert result == RESULT_PART_2
contents = TEST_FILE_P2.read_text()
result = part2(contents)
assert result == EXPECTED_PART_2

0 comments on commit 3ac7db0

Please sign in to comment.