Skip to content

Commit 9825d8b

Browse files
committed
[2018] Use private inputs
1 parent 348efc0 commit 9825d8b

File tree

23 files changed

+183
-45
lines changed

23 files changed

+183
-45
lines changed

2018/day01/test_day01.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day01 import calculate_frequency, calculate_frequency_two_match
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117

1218

1319
def test_part1():
@@ -17,7 +23,7 @@ def test_part1():
1723
assert calculate_frequency(['+1', '+1', '-2']) == 0
1824
assert calculate_frequency(['-1', '-2', '-3']) == -6
1925

20-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
26+
with open(_INPUT_FILE, 'r') as input_file:
2127
file_content = input_file.readlines()
2228
assert calculate_frequency(file_content) == 477
2329

@@ -30,6 +36,6 @@ def test_part2():
3036
assert calculate_frequency_two_match(['-6', '+3', '+8', '+5', '-6']) == 5
3137
assert calculate_frequency_two_match(['+7', '+7', '-2', '-7', '-4']) == 14
3238

33-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
39+
with open(_INPUT_FILE, 'r') as input_file:
3440
file_content = input_file.readlines()
3541
assert calculate_frequency_two_match(file_content) == 390

2018/day02/test_day02.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day02 import calculate_checksum, find_correct_id
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117

1218

1319
def test_part1():
@@ -22,7 +28,7 @@ def test_part1():
2228
'ababab',
2329
]) == 12
2430

25-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
31+
with open(_INPUT_FILE, 'r') as input_file:
2632
file_content = input_file.readlines()
2733
assert calculate_checksum(file_content) == 9633
2834

@@ -39,6 +45,6 @@ def test_part2():
3945
'wvxyz',
4046
]) == 'fgij'
4147

42-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
48+
with open(_INPUT_FILE, 'r') as input_file:
4349
file_content = input_file.readlines()
4450
assert find_correct_id(file_content) == 'lujnogabetpmsydyfcovzixaw'

2018/day03/test_day03.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day03 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117

1218
_TEST_DATA = [
1319
'#1 @ 1,3: 4x4',
@@ -20,7 +26,7 @@ def test_part1():
2026
"""Tests for Part 1."""
2127
assert run_part1(_TEST_DATA) == 4
2228

23-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
29+
with open(_INPUT_FILE, 'r') as input_file:
2430
file_content = input_file.readlines()
2531
assert run_part1(file_content) == 108961
2632

@@ -29,6 +35,6 @@ def test_part2():
2935
"""Tests for Part 2."""
3036
assert run_part2(_TEST_DATA) == 3
3137

32-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
38+
with open(_INPUT_FILE, 'r') as input_file:
3339
file_content = input_file.readlines()
3440
assert run_part2(file_content) == 681

2018/day04/test_day04.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day04 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = [
1218
'[1518-11-01 00:05] falls asleep',
1319
'[1518-11-03 00:29] wakes up',
@@ -33,7 +39,7 @@ def test_part1():
3339
"""Tests for Part 1."""
3440
assert run_part1(_TEST_DATA) == 240
3541

36-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
42+
with open(_INPUT_FILE, 'r') as input_file:
3743
file_content = input_file.readlines()
3844
assert run_part1(file_content) == 73646
3945

@@ -42,6 +48,6 @@ def test_part2():
4248
"""Tests for Part 2."""
4349
assert run_part2(_TEST_DATA) == 4455
4450

45-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
51+
with open(_INPUT_FILE, 'r') as input_file:
4652
file_content = input_file.readlines()
4753
assert run_part2(file_content) == 4727

2018/day05/test_day05.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day05 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117

1218

1319
def test_part1():
@@ -22,7 +28,7 @@ def test_part1():
2228
assert run_part1('dabAcCaCBAcCcaDAa') == 9
2329
assert run_part1('DdabAcCaCBAcCcaDAa') == 8
2430

25-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
31+
with open(_INPUT_FILE, 'r') as input_file:
2632
file_content = input_file.read().strip()
2733
assert run_part1(file_content) == 11894
2834

@@ -31,6 +37,6 @@ def test_part2():
3137
"""Tests for Part 2."""
3238
assert run_part2('dabAcCaCBAcCcaDA') == 4
3339

34-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
40+
with open(_INPUT_FILE, 'r') as input_file:
3541
file_content = input_file.read().strip()
3642
assert run_part2(file_content) == 5310

2018/day06/test_day06.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day06 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = [
1218
'1, 1',
1319
'1, 6',
@@ -22,7 +28,7 @@ def test_part1():
2228
"""Tests for Part 1."""
2329
assert run_part1(_TEST_DATA) == 17
2430

25-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
31+
with open(_INPUT_FILE, 'r') as input_file:
2632
file_content = input_file.readlines()
2733
assert run_part1(file_content) == 3251
2834

@@ -31,6 +37,6 @@ def test_part2():
3137
"""Tests for Part 2."""
3238
assert run_part2(_TEST_DATA, 32) == 16
3339

34-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
40+
with open(_INPUT_FILE, 'r') as input_file:
3541
file_content = input_file.readlines()
3642
assert run_part2(file_content, 10000) == 47841

2018/day07/test_day07.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day07 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = [
1218
'Step C must be finished before step A can begin.',
1319
'Step C must be finished before step F can begin.',
@@ -23,7 +29,7 @@ def test_part1():
2329
"""Tests for Part 1."""
2430
assert run_part1(_TEST_DATA) == 'CABDFE'
2531

26-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
32+
with open(_INPUT_FILE, 'r') as input_file:
2733
file_content = input_file.readlines()
2834
assert run_part1(file_content) == 'GLMVWXZDKOUCEJRHFAPITSBQNY'
2935

@@ -32,6 +38,6 @@ def test_part2():
3238
"""Tests for Part 2."""
3339
assert run_part2(_TEST_DATA, 2, 0) == 15
3440

35-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
41+
with open(_INPUT_FILE, 'r') as input_file:
3642
file_content = input_file.readlines()
3743
assert run_part2(file_content, 5, 60) == 1105

2018/day08/test_day08.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
from .day08 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = '2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2'
1218

1319

1420
def test_part1():
1521
"""Tests for Part 1."""
1622
assert run_part1(_TEST_DATA) == 138
1723

18-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
24+
with open(_INPUT_FILE, 'r') as input_file:
1925
file_content = input_file.read().strip()
2026
assert run_part1(file_content) == 42472
2127

@@ -24,6 +30,6 @@ def test_part2():
2430
"""Tests for Part 2."""
2531
assert run_part2(_TEST_DATA) == 66
2632

27-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
33+
with open(_INPUT_FILE, 'r') as input_file:
2834
file_content = input_file.read().strip()
2935
assert run_part2(file_content) == 21810

2018/day09/test_day09.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day09 import run_part1, run_part2
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = [
1218
('9 players; last marble is worth 25 points', 32),
1319
('10 players; last marble is worth 1618 points', 8317),
@@ -23,13 +29,13 @@ def test_part1():
2329
for (instruction, high_score) in _TEST_DATA:
2430
assert run_part1(instruction) == high_score
2531

26-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
32+
with open(_INPUT_FILE, 'r') as input_file:
2733
file_content = input_file.read().strip()
2834
assert run_part1(file_content) == 399745
2935

3036

3137
def test_part2():
3238
"""Tests for Part 2."""
33-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
39+
with open(_INPUT_FILE, 'r') as input_file:
3440
file_content = input_file.read().strip()
3541
assert run_part2(file_content) == 3349098263

2018/day10/test_day10.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from .day10 import find_message
99

1010
_CURRENT_FILE_DIR = path.dirname(__file__)
11+
_INPUT_FILE = path.join(
12+
path.dirname(path.dirname(_CURRENT_FILE_DIR)),
13+
'private',
14+
'inputs',
15+
'2018',
16+
path.basename(_CURRENT_FILE_DIR) + '.txt')
1117
_TEST_DATA = [
1218
'position=< 9, 1> velocity=< 0, 2>',
1319
'position=< 7, 0> velocity=<-1, 0>',
@@ -71,7 +77,7 @@ def test_find_message():
7177
assert message == _TEST_EXPECTED
7278
assert seconds == 3
7379

74-
with open(path.join(_CURRENT_FILE_DIR, 'input'), 'r') as input_file:
80+
with open(_INPUT_FILE, 'r') as input_file:
7581
message, seconds = find_message(input_file.readlines())
7682
assert message == _INPUT_EXPECTED
7783
assert seconds == 10886

0 commit comments

Comments
 (0)