-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
56 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
from y_2015.day1 import calculate_1, calculate_2 | ||
from __future__ import annotations | ||
|
||
from unittest.mock import mock_open, patch | ||
|
||
from y_2015.day1 import Day | ||
|
||
with patch("builtins.open", mock_open(read_data="0")): | ||
day = Day() | ||
|
||
|
||
def test_calculate_1(): | ||
assert calculate_1("(())") == 0 | ||
assert calculate_1("()()") == 0 | ||
assert calculate_1("(((") == 3 | ||
assert calculate_1("(()(()(") == 3 | ||
assert calculate_1("))(((((") == 3 | ||
assert calculate_1("())") == -1 | ||
assert calculate_1("))(") == -1 | ||
assert calculate_1(")))") == -3 | ||
assert calculate_1(")())())") == -3 | ||
day._Day__input_data = "(())" | ||
assert day._calculate_1() == 0 | ||
|
||
day._Day__input_data = "(((" | ||
assert day._calculate_1() == 3 | ||
|
||
day._Day__input_data = "(()(()(" | ||
assert day._calculate_1() == 3 | ||
|
||
day._Day__input_data = "))(((((" | ||
assert day._calculate_1() == 3 | ||
|
||
day._Day__input_data = "())" | ||
assert day._calculate_1() == -1 | ||
|
||
day._Day__input_data = "))(" | ||
assert day._calculate_1() == -1 | ||
|
||
day._Day__input_data = ")))" | ||
assert day._calculate_1() == -3 | ||
|
||
day._Day__input_data = ")())())" | ||
assert day._calculate_1() == -3 | ||
|
||
|
||
def test_calculate_2(): | ||
assert calculate_2(")") == 1 | ||
assert calculate_2("()())") == 5 | ||
assert calculate_2("(") == -1 | ||
day._Day__input_data = ")" | ||
assert day._calculate_2() == 1 | ||
|
||
day._Day__input_data = "()())" | ||
assert day._calculate_2() == 5 | ||
|
||
day._Day__input_data = "(" | ||
assert day._calculate_2() == -1 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
from common.aoc import AoCDay | ||
|
||
OPERATIONS = {"(": 1, ")": -1} | ||
|
||
|
||
def calculate_1(i: str) -> int: | ||
return sum(OPERATIONS[x] for x in i) | ||
class Day(AoCDay): | ||
def __init__(self, test=0): | ||
super().__init__(__name__, test) | ||
|
||
def _preprocess_input(self): | ||
self.__input_data = self._input_data[0][0] | ||
|
||
def _calculate_1(self): | ||
return sum(OPERATIONS[x] for x in self.__input_data) | ||
|
||
def calculate_2(i: str) -> int: | ||
result = 0 | ||
for j, x in enumerate(i, start=1): | ||
result += OPERATIONS[x] | ||
if result == -1: | ||
return j | ||
return -1 | ||
def _calculate_2(self): | ||
result = 0 | ||
for j, x in enumerate(self.__input_data, start=1): | ||
result += OPERATIONS[x] | ||
if result == -1: | ||
return j | ||
return -1 |