コード例 #1
0
def test_part1():
    password = '******'
    with open('input.txt') as f:
        instructions = f.readlines()
    scrambler = Scrambler(instructions)
    scrambled = scrambler.scramble(password)
    assert scrambled == 'baecdfgh'
コード例 #2
0
def test_part2():
    scrambled = 'fbgdceah'

    with open('input.txt') as f:
        instructions = f.readlines()
    scrambler = Scrambler(instructions)

    unscrambled = scrambler.unscramble(scrambled)
    assert unscrambled == 'cegdahbf'
コード例 #3
0
def test_reverse():
    # reverse positions X through Y means that the span of letters at indexes X through Y (including the letters at X
    # and Y) should be reversed in order.
    password = '******'
    output = Scrambler.reverse(password, 1, 3, _=False)
    assert output == 'adcbefgh'
    output = Scrambler.reverse(password, 0, 4, _=False)
    assert output == 'edcbafgh'
    output = Scrambler.reverse(password, 5, 7, _=False)
    assert output == 'abcdehgf'
コード例 #4
0
def test_rotate_letter():
    # rotate based on position of letter X means that the whole string should be rotated to the right based on the index
    #   of letter X (counting from 0) as determined before this instruction does any rotations. Once the index is
    #   determined, rotate the string to the right one time, plus a number of times equal to that index, plus one
    #   additional time if the index was at least 4.
    password = '******'
    output = Scrambler.rotate_letter(password, 'b', invert=False)
    assert output == 'ecabd'
    output = Scrambler.rotate_letter(output, 'd', invert=False)
    assert output == 'decab'
コード例 #5
0
def test_move():
    # move position X to position Y means that the letter which is at index X should be removed from the string, then
    # inserted such that it ends up at index Y.
    password = '******'
    output = Scrambler.move(password, 1, 3, invert=False)
    assert output == 'acdbefgh'
コード例 #6
0
def test_rotate_steps():
    # rotate left/right X steps means that the whole string should be rotated; for example, one right rotation would
    # turn abcd into dabc.
    password = '******'
    output = Scrambler.rotate(password, -1, invert=False)
    assert output == 'eabcd'
コード例 #7
0
def test_swap_letter():
    # swap letter X with letter Y means that the letters X and Y should be swapped (regardless of where they appear in
    #   the string).
    password = '******'
    output = Scrambler.swap_letter(password, 'c', 'd', _=False)
    assert output == 'abdce'
コード例 #8
0
def test_swap_pos():
    # swap position X with position Y means that the letters at indexes X and Y (counting from 0) should be swapped.
    password = '******'
    output = Scrambler.swap_pos(password, 1, 2, invert=False)
    assert output == 'acbde'
コード例 #9
0
def check_unscrambling(instructions, password, scrambled_password):
    scrambler = Scrambler(instructions)
    unscrambled = scrambler.unscramble(scrambled_password)
    assert unscrambled == password
コード例 #10
0
def check_scrambling(instructions, password, expected):
    scrambler = Scrambler(instructions)
    scrambled = scrambler.scramble(password)
    assert scrambled == expected