コード例 #1
0
def test_5():
    compressed = '(6x1)(1x3)A'  # simply becomes (1x3)A - the (1x3) looks like a marker,
    # but because it's within a data section of another marker, it is not treated any
    # differently from the A that comes after it. It has a decompressed length of 6.
    dec, length = day9.decompress(compressed)
    assert length == 6
    assert dec == '(1x3)A'
コード例 #2
0
def test_6():
    compressed = 'X(8x2)(3x3)ABCY'  # becomes X(3x3)ABC(3x3)ABCY (for a decompressed length of 18),
    # because the decompressed data from the (8x2) marker (the (3x3)ABC) is skipped and
    # not processed further.
    dec, length = day9.decompress(compressed)
    assert length == 18
    assert dec == 'X(3x3)ABC(3x3)ABCY'
コード例 #3
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Example_5(self):
     string = 'A(2x2)BCD(2x2)EFG'
     self.assertEqual(day9.decompress(string), 11)
コード例 #4
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Example_3(self):
     string = '(3x3)XYZ'
     self.assertEqual(day9.decompress(string), 9)
コード例 #5
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Example_2(self):
     string = 'A(1x5)BC'
     self.assertEqual(day9.decompress(string), 7)
コード例 #6
0
def test_2():
    compressed = 'A(1x5)BC'  # repeats only the B a total of 5 times, becoming
    # ABBBBBC for a decompressed length of 7.
    dec, length = day9.decompress(compressed)
    assert length == 7
    assert dec == 'ABBBBBC'
コード例 #7
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_2_Data(self):
     with open('input.txt') as f:
         data = f.read()
     self.assertEqual(day9.decompress(data, True), 11125026826)
コード例 #8
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_2Example_3(self):
     string = '(27x12)(20x12)(13x14)(7x10)(1x12)A'
     self.assertEqual(day9.decompress(string, True), 241920)
コード例 #9
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_2Example(self):
     string = '(3x3)XYZ'
     self.assertEqual(day9.decompress(string, True), 9)
コード例 #10
0
def test_v2_1():
    compressed = '(3x3)XYZ'  # still becomes XYZXYZXYZ, as the decompressed section contains no markers.
    _, length = day9.decompress(compressed, v2=True)
    assert length == len('XYZXYZXYZ')
コード例 #11
0
def test_part1():
    with open('day9_input.txt') as file:
        compressed = file.read().strip()
    _, length = day9.decompress(compressed)
    assert length == 102239
コード例 #12
0
def test_1():
    compressed = 'ADVENT'  # contains no markers and decompresses to itself with no changes,
    # resulting in a decompressed length of 6.
    dec, length = day9.decompress(compressed)
    assert length == 6
    assert dec == 'ADVENT'
コード例 #13
0
def test_4():
    compressed = 'A(2x2)BCD(2x2)EFG'  # doubles the BC and EF, becoming ABCBCDEFEFG
    # for a decompressed length of 11.
    dec, length = day9.decompress(compressed)
    assert length == 11
    assert dec == 'ABCBCDEFEFG'
コード例 #14
0
def test_3():
    compressed = '(3x3)XYZ'  # becomes XYZXYZXYZ for a decompressed length of 9.
    dec, length = day9.decompress(compressed)
    assert length == 9
    assert dec == 'XYZXYZXYZ'
コード例 #15
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Example_6(self):
     string = '(6x1)(1x3)A'
     self.assertEqual(day9.decompress(string), 6)
コード例 #16
0
def test_v2_2():
    compressed = 'X(8x2)(3x3)ABCY'  # becomes XABCABCABCABCABCABCY, because the decompressed data from the (8x2)
    # marker is then further decompressed, thus triggering the (3x3) marker twice for a total of six ABC sequences.
    _, length = day9.decompress(compressed, v2=True)
    assert length == len('XABCABCABCABCABCABCY')
コード例 #17
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Data(self):
     with open('input.txt') as f:
         data = f.read()
     self.assertEqual(day9.decompress(data), 138735)
コード例 #18
0
def test_v2_3():
    compressed = '(27x12)(20x12)(13x14)(7x10)(1x12)A'  # decompresses into a string of A repeated 241920 times.
    _, length = day9.decompress(compressed, v2=True)
    assert length == 241920
コード例 #19
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_2Example_2(self):
     string = 'X(8x2)(3x3)ABCY'
     self.assertEqual(day9.decompress(string, True),
                      len('XABCABCABCABCABCABCY'))
コード例 #20
0
def test_v2_4():
    compressed = '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'  # becomes 445 characters long.
    _, length = day9.decompress(compressed, v2=True)
    assert length == 445
コード例 #21
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_2Example_4(self):
     string = '(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN'
     self.assertEqual(day9.decompress(string, True), 445)
コード例 #22
0
def test_part2():
    with open('day9_input.txt') as file:
        compressed = file.read().strip()
    _, length = day9.decompress(compressed, v2=True)
    assert length == 10780403063
コード例 #23
0
ファイル: tests.py プロジェクト: willismonroe/adventofcode
 def test_Day9_Example(self):
     string = 'ADVENT'
     self.assertEqual(day9.decompress(string), 6)
コード例 #24
0
def test_examples(data, transformed):
    assert decompress(data) == transformed