-
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.
Merge pull request #193 from Stegallo/2015_8
day8
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from unittest.mock import mock_open, patch | ||
|
||
from y_2015.day8 import Day | ||
|
||
with patch("builtins.open", mock_open(read_data="")): | ||
day = Day() | ||
|
||
|
||
def test_calculate_1(): | ||
day._Day__input_data = ['""', '"abc"', '"aaa\\"aaa"', '"\\x27"'] | ||
assert day._calculate_1() == 12 | ||
|
||
|
||
def test_calculate_2(): | ||
day._Day__input_data = ['""', '"abc"', '"aaa\\"aaa"', '"\\x27"'] | ||
assert day._calculate_2() == 19 |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from common.aoc import AoCDay | ||
|
||
|
||
class Day(AoCDay): | ||
def __init__(self, test=0): | ||
super().__init__(__name__, test) | ||
|
||
def _preprocess_input(self): | ||
self.__input_data = self._input_data[0] | ||
|
||
def _calculate_1(self): | ||
string_len = sum(len(x) for x in self.__input_data) | ||
mem_len = sum(len(eval(x)) for x in self.__input_data) | ||
return string_len - mem_len | ||
|
||
def _calculate_2(self): | ||
return sum(2 + x.count("\\") + x.count('"') for x in self.__input_data) |